Call (Thisobj,arg1,arg2 ...), apply (Thisobj,[obj1,obj2 ...]) These two methods are non-inherited methods that each function contains
Call (thisobj[, args]) and apply (thisobj[, args])
The action is the same, simply to change the current object in the method using this point, point to the Thisobj object in the calling method the difference between the two (the first parameter is the same) is the call method passed in the parameters are listed, And the second parameter in the Apply method is an array
Or an example of the more intuitive:
Window.color= ' Red ';
var o={color: "Blue"};
function Saycolor () {
alert (This.color);
};
Saycolor (); Red (global function, this is window)
Saycolor.call (this);//red (Invoke Call method, specify object is this, here is window, no meaning)
Saycolor.call (window);//red (call method is called, specifies that the object is window, it doesn't make sense)
Saycolor.call (o); Blue (call method is called, the specified object is O, so this refers to the object o, where the original window points to O)
Saycolor.apply (o);//blue (call method is called, the specified object is O, so this refers to the object o, where the original window points to O)
The bind () method in ECMAScript5 is similar to the first two methods, and the bind () method creates an instance of a function that is bound to the value passed to the bind () function.
Example:
function A (y) {
return this.x+y;
};
var o={x:1};
var g=a.bind (o);
g (2);//3
From the example, we can see that function A is bound to the object o, and the new function g is returned, and when G is called, a function is called as the object O method.
Bind () This method binds a function to an object and returns a new function in which the parameters passed into the new function are passed to the bound function.
A brief description of call (), apply (), bind ()