Read the source code of the various frameworks the apply and call methods must often see that a good understanding of the concept is crucial.
Functions in JavaScript are also objects, which are no different from other JavaScript objects, and function objects can also contain methods. The call () method and the Apply () method can indirectly invoke the function. Two methods allow you to explicitly specify the this value that is required for the invocation, that is, any function can be invoked as a method of any object, even if the function is not a method of that object.
Two methods can specify the arguments that are called. The call () method uses its own argument list as the argument for the function, and the Apply () method requires that the parameter be passed in as an array.
The first argument of the call () method and the Apply () method is the parent object that is to invoke the function, which is the emphasis context through which this is used in the body of the function to obtain a reference to it.
function A1 (i,j) { var a = 1; Console.log (a); Console.log (I,J);} function B1 (i,j) { var b = 2; Console.log (i,j); This (I,J);} B1.call (A1,111,222); Call () method invocation // b1.apply (a1,[111,222]), apply () method call, same as, only the form of the argument is not the same
The call () method of the function and the Apply () method