$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. 代碼如下: //就是用一個循環(huán)嵌套try...catch完成這個工具函數(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; } };
看一個例子(不同的瀏覽器有不同的創(chuàng)建XMLHttpRequest的方法): 代碼如下: getTransport: function() { return Try.these( function() { return new XMLHttpRequest() }, function() { return new ActiveXObject('Msxml2.XMLHTTP') }, function() { return new ActiveXObject('Microsoft.XMLHTTP') } ) || false; }