One JavaScript instance-apply and call every day, javascript-apply
<! DOCTYPE html>
What are the differences between the apply () and call () methods in javascript?
Call and apply all belong to Function. A prototype method is implemented internally by the JavaScript engine because it belongs to the Function. prototype, so each Function object instance, that is, each method has the call and apply attribute. since they are attributes of methods, their use is of course for methods. these two methods are easy to confuse, because they have the same effect, but they are used in different ways.
Similarities: the two methods have the same effect.
Differences: parameters passed by methods are different.
Javascript call apply is not understood
Call and apply can be called using variables as function names. For example, the callback function of a function. The specific usage is: executed function. call (a, B, c ...), a is the object that this needs to be specified in the executed function. It can be null. Other parameters are used as parameters of the executed function. The usage of apply is similar, but the second parameter is an array.
Example:
Function doPost (url, param, callback ){
// Process post requests here
Var str = xhr. responseText;
Callback. apply (this, [str]); // It is equivalent to calling callback (str); and setting this in callback as a doPost object
}