欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Prototype 工具函數(shù) 學(xué)習(xí)

 更新時(shí)間:2009年07月23日 23:24:00   作者:  
Prototype學(xué)習(xí)工具函數(shù)$H,$R,Try.these,document.getElementsByClassName
$H就是建立Hash對象的便捷方法,關(guān)于Hash對象具體參考【Prototype 學(xué)習(xí)——Hash對象 】
$R就是簡歷ObjectRange對象的便捷方法,關(guān)于ObjectRange對象具體參考【Prototype 學(xué)習(xí)——ObjectRange對象 】
Try.these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
復(fù)制代碼 代碼如下:

//就是用一個(gè)循環(huán)嵌套try...catch完成這個(gè)工具函數(shù)的
var Try = {
these: function() {
var returnValue;
for (var i = 0, length = arguments.length; i < length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) { }
}
return returnValue;
}
};

看一個(gè)例子(不同的瀏覽器有不同的創(chuàng)建XMLHttpRequest的方法):
復(fù)制代碼 代碼如下:

getTransport: function() {
return Try.these(
function() { return new XMLHttpRequest() },
function() { return new ActiveXObject('Msxml2.XMLHTTP') },
function() { return new ActiveXObject('Microsoft.XMLHTTP')
} ) || false; }

document.getElementsByClassName():
根據(jù)這個(gè)方法的名字大概就能猜到這個(gè)方法的用途了。但是這個(gè)方法在1.6里面被標(biāo)記成
deprecated的了。被$$和Eelement.select方法代替了,關(guān)于這兩個(gè)方法,后面在講。

相關(guān)文章

最新評論