Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.
Syntaxapply([ thisObj [, argArray ]])
The following code shows how to use the apply method.
function callMe(arg1, arg2){
var s = "";
s += "this value: " + this;
s += "<br />";
for (i in callMe.arguments) {
s += "arguments: " + callMe.arguments[i];
s += "<br />";
}
return s;
}
document.write("Original function: <br/>");
document.write(callMe(1, 2));
document.write("<br/>");
document.write("Function called with apply: <br/>");
document.write(callMe.apply(3, [ 4, 5 ]));
Remarks
If argArray is not a valid object, then an “Object expected” error occurs.
If neither argArray nor thisObj are supplied, the original this object is used as thisObj and no arguments are passed.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4