Same point:
- Each function contains these two native methods
- The effect of both of them is the same, for executing functions under a specific scope, essentially setting the value of this object within the function.
Different points:
- The parameter types passed in are different. Apply (function scope, array[parameter]), call (function scope, parameter 1, parameter 2, Parameter 3 ...). Note: The function scope parameter does not pass or NULL, the default is window, and in strict mode is undefined, which is an invalid scope.
Application Scenarios:
Add:
- A method bind () is also defined in ECMAScript 5, which creates an instance of a function whose this value is bound to the value passed to the bind () function.
- Example
Window.color = "Red"; var o = (color: "Blue" ); function Saycolor () {alert (this. color); var Objectsaycolor = Saycolor.bind (o);
Objectsaycolor ();///Blue
Browsers that support the bind () method are ie9+, firefox4+, Safari 5.1+, Opera 12+, and Chrome.
Reference:
- Https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
[Solve a problem every day series-0001] Javascript Apply and call comparison