Read the description of the call and apply method in the JS authoritative guide: we can call () and apply () as a method of an object, calling the function indirectly in the form of a calling method. This explanation is a bit confusing. Here's your opinion: in fact, call and apply are literally meant to represent the callback of a function, in fact, the use and AS3 of the same call and apply. Where the first parameter of call () is the same as the first parameter of apply (), which represents the parent object of the function to be called, he is the context of the call, and in the body of the function obtains a reference to him by using this. The rest of the call () parameter is the argument list to be passed to the called function. Apply () A parameter other than the first argument is passed to the argument of the calling function, except that he is in the form of an array, and the parameter list of call () is different.
To invoke the function fu () as an object Ob method, you can use call and apply.
Fu.call (OB); fu.apply (OB);
In strict mode, the first parameter of call and apply will change to the value of this. Even if the actual argument passed in is the original value or null,undefined. Null and undefined passed in non-strict mode are replaced by global objects, and the original values are replaced by the corresponding wrapper objects.
Example one:
var func=new function () {this . A= "func" Span style= "color: #0000ff;" >var myfunc=function (x) { var a= "MyFunc" ; var b = "bbbbb" ; Alert ( this .b); Alert ( this .a); alert (x); } myfunc.call (func, "var"); *//* var Nu = Math.max.apply (math,[1,3,4,6,7]); Alert (NU);
Example two:
var nu = Math.max.apply (math,[1,3,4,6,7]); alert (NU);
Example three:
function Add (A, b) { + b); } function Sub (A, b) { - b); } 3, 1);
Run to see what the results are, and you'll understand.
Http://www.cnblogs.com/huyong/p/4139875.html
The call and apply in JS