var obj = {name: "Zhang San"} function fn () { Console.log (this) } fn (); // Obj.fn is not a function fn.call (obj) /// First we let the call method on the prototype execute, and when we execute the call method, we make the this in the FN method the first parameter value obj And then execute the FN function.
// Self-simulates the built-in call method, writing a Mycall method to delve into the call principle Function.prototype.myCall = function ( Context) { /* Mycall method T His is the name of the function in which I want to manipulate and change the This keyword so that the "this keyword" in this function becomes the context * / // 1, let the This keyword in FN change to the value of the context->obj
eval (this . toString (). Replace (' This '
// first fn1 to find the call method on the Function.prototype through the prototype chain mechanism, and let call () method execution, and this is the method that I want to operate the FN1, In the call method code execution, first let the "this keyword" in fn1 into fn2, and then let this method execute->1 fn1.call.call (fn2) /* first, the call method on the Function.prototype is found through the prototype chain mechanism, and then the call method is found on the function prototype by the prototype FN1 (because the value of call itself is also an So the same can be found Function.prototype), the second time to find the call to the method to execute, the method of this is Fn1.call, and then let this method of this into fn2, and finally Fn1.call execution->2 */
JS Learning Summary----Call method in depth