Reprint: Http://msdn.microsoft.com/zh-cn/library/4zc42wh1 (v=vs.94). aspx
Write in front: similar to the call method
Invokes the function and replaces the function's this value with the specified object , replacing the function's arguments with the specified array.
Apply ([Thisobj[,argarray]])
Parameters
Thisobj
Optional. the object to use as the This object.
Argarray
Optional. a set of parameters to pass to the function.
Note
If Argarray is not a valid object, an "expected object" error appears.
If neither Argarray nor Thisobj is provided , the original this object will be used as thisobj and no parameters will be passed.
Example
The following code shows how to use the Apply method.
1 functioncallMe (arg1, arg2) {2Console.log (' This value: ' + This);3 for(varIinchcallme.arguments) {4Console.log (' arguments: ' +Callme.arguments[i])5 }6 }7 8CallMe (1, 2);9 //This value: [Object Window]Ten //arguments:1 One //Arguments:2 A -Callme.apply (' A ', [' B ', ' C ']) - //This value:a the //arguments:b - //Arguments:c
Requirements
Supported in the following document modes: Quirks, Internet Explorer 6 standard mode, Internet Explorer 7 Standard mode, Internet Explorer 8 standard mode, Internet Explorer 9 standard mode, INT Ernet Explorer 10 Standard mode and Internet Explorer 11 standard mode. In addition, it is also supported in store apps (Windows 8 and Windows Phone 8.1).
Apply Method (Function) (JavaScript)