$H is a convenient way to create a Hash object. For specific references to Hash objects [Prototype Learning - Hash Objects]
$R is a convenient method for resume ObjectRange objects. For specific references to ObjectRange objects [Prototype Learning - ObjectRange Object]
:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
//It is to use a loop to nest try...catch to complete this tool function
var Try = {
these: function() {
var returnValue;
for (var i = 0, length = ; i < length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) { }
}
return returnValue;
}
};
See an example (different browsers have different methods to create XMLHttpRequest):
getTransport: function() {
return (
function() { return new XMLHttpRequest() },
function() { return new ActiveXObject('') },
function() { return new ActiveXObject('')
} ) || false; }
():
Based on the name of this method, you can roughly guess the purpose of this method. But this method is marked as
Deprecated. It has been replaced by $$ and methods. Regarding these two methods, we will talk about them later.
$R is a convenient method for resume ObjectRange objects. For specific references to ObjectRange objects [Prototype Learning - ObjectRange Object]
:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
Copy the codeThe code is as follows:
//It is to use a loop to nest try...catch to complete this tool function
var Try = {
these: function() {
var returnValue;
for (var i = 0, length = ; i < length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) { }
}
return returnValue;
}
};
See an example (different browsers have different methods to create XMLHttpRequest):
Copy the codeThe code is as follows:
getTransport: function() {
return (
function() { return new XMLHttpRequest() },
function() { return new ActiveXObject('') },
function() { return new ActiveXObject('')
} ) || false; }
():
Based on the name of this method, you can roughly guess the purpose of this method. But this method is marked as
Deprecated. It has been replaced by $$ and methods. Regarding these two methods, we will talk about them later.