Apply and call methods are identical, are used to change the method of the This keyword, and the method of execution: and in strict mode and non-strict mode for the first parameter is null/undefined the law of this situation is the same;
Bind: This method is incompatible with ie6-8 and call and apply are used to change the This keyword
' Use strict '//tell the current browser that the next JS code will be written in strict mode varobj = {name: ' Zhang San '} functionfn (num1,num2) {Console.log (Num1+num2); Console.log ( This)} fn (100,200);//This ->window num1=100 num2=200Fn.call (100,200);//this->100 num1 = num2=undefined NaNFn.call (obj,100,200)//This->obj Call When the parameter is passed to FN, it is passed a value, and apply is not a pass, but the parameter value to be passed in an array to operate. But it's also equivalent to assigning a parameter to FN.Fn.apply (obj,[100,200]);// //pre-processing: The FN's this change in advance to the results we want, and the corresponding parameter values are also ready for use later, the direct execution can be. Bind here to achieve the effect of preprocessing varTEMPFN = Fn.bind (obj,100,200);//just changed the this in FN to obj, and the FN passed two parameter values 100 and 200, but at this time does not have the FN function, execute bind will have a return value, this return value TEMPFN is we put FN's this change after the resultTEMPFN (); Fn.call ();//This->window in strict mode this->undefinedFn.call (NULL);//This->window in strict mode this->nullFn.call (undefined)//This->window in strict mode this->undefined
JS Learning Summary----The difference between call and apply and bind