| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
call Method (Function) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
fa356dec-48e6-4f75-8bf3-c1814a76818f |
10 |
mikejo5000 |
mikejo |
ghogen |
Calls a method of an object, substituting another object for the current object.
call([thisObj[, arg1[, arg2[, [, argN]]]]])
thisObj
Optional. The object to be used as the current object.
arg1, arg2, , argN
Optional. A list of arguments to be passed to the method.
The call method is used to call a method on behalf of another object. It allows you to change the this object of a function from the original context to the new object specified by thisObj.
If thisObj is not supplied, the global object is used as thisObj.
The following code shows how to use the call 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 call: <br/>");
document.write(callMe.call(3, 4, 5));
// Output:
// Original function:
// this value: [object Window]
// arguments: 1
// arguments: 2
// Function called with call:
// this value: 3
// arguments: 4
// arguments: 5
[!INCLUDEjsv55]