Prototype 工具函數 學習_prototype

來源:互聯網
上載者:User
$H就是建立Hash對象的便捷方法,關於Hash對象具體參考【Prototype 學習——Hash對象 】
$R就是簡曆ObjectRange對象的便捷方法,關於ObjectRange對象具體參考【Prototype 學習——ObjectRange對象 】
Try.these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
複製代碼 代碼如下:

//就是用一個迴圈嵌套try...catch完成這個工具函數的
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;
}
};

看一個例子(不同的瀏覽器有不同的建立XMLHttpRequest的方法):
複製代碼 代碼如下:

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

document.getElementsByClassName():
根據這個方法的名字大概就能猜到這個方法的用途了。但是這個方法在1.6裡面被標記成
deprecated的了。被$$和Eelement.select方法代替了,關於這兩個方法,後面在講。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.