Home > Web Front-end > JS Tutorial > Prototype tool function learning_prototype

Prototype tool function learning_prototype

WBOY
Release: 2016-05-16 18:49:16
Original
1263 people have browsed it

$H is a convenient method to create a Hash object. For details on the Hash object, please refer to [Prototype Learning - Hash Object]
$R is a convenient method to create an ObjectRange object. For details on the ObjectRange object, please refer to [Prototype Learning - ObjectRange Object]
Try.these:
Accepts an arbitrary number of functions and returns the result of the first one that doesn't throw an error.

Copy code The code is as follows:

//Use a loop nested try...catch to complete this tool function
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;
}
};

Look at an example (different browsers have different ways of creating XMLHttpRequest):
Copy the code The 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():
According to this You can probably guess the purpose of this method from the name of the method. But this method was marked
deprecated in 1.6. Replaced by the $$ and Eelement.select methods. These two methods will be discussed later.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template