1. Call method
First Little Demo:
<span style= "FONT-SIZE:14PX;" >function Add (A, b) {alert (a+b),} function sub (a, b) {alert (A-a);} <span style= "color: #ff6600;" >add</span>.call (sub,2,1); </span>
I believe that after this demo, we all understand that the Add () method is used to replace the sub ()Method, Add.call (sub,3,1) = = Add (3,1), so the result is: Alert (3)
2. Apply method
The Apply method is actually the same as the call method , only slightly different on the parameter: (that is , the second argument passed in by the Apply method must be an array of arguments , That is, if the Apply method is more than two arguments, then all parameters after the second parameter must be passed in as an array , and the first parameter remains the same as the call method )
The obj.call (ARG,AAA,BBB,CCC) method corresponds to the Apply notation:obj. Apply (arg, [AAA,BBB,CCC]) , the effect of both is the same.
The difference between call and apply method in JS