$ H is a convenient way to create Hash objects. For details about Hash objects, refer to Prototype Learning-Hash objects]
$ R is a convenient method for resume ObjectRange objects. For details about ObjectRange objects, refer to [Prototype Learning-ObjectRange objects]
Try. these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.
Copy codeThe Code is as follows:
// Use a loop nested try... catch to complete the function of this tool.
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;
}
};
Let's look at an example (different browsers have different methods for creating XMLHttpRequest ):
Copy codeThe Code is as follows:
GetTransport: function (){
Return Try. these (
Function () {return new XMLHttpRequest ()},
Function () {return new ActiveXObject ('msxml2. xmlhttp ')},
Function () {return new ActiveXObject ('Microsoft. xmlhttp ')
}) | False ;}
Document. getElementsByClassName ():
You can probably guess the purpose of this method based on the method name. However, this method is marked
Deprecated. It is replaced by the $ and Eelement. select methods. The two methods are described later.