The this point in JS (a few simpler):
1. This point of the normal function points to the window;
The 2 object method points to the current object;
3. () = "Arrow function points to the object when defined;
Apply and call can change the current this point, but cannot change the direction of the arrow function
functionfoo () {return() = { return() = { return() ={Console.log (' ID: ', This. ID); }; }; };}varF = Foo.call ({id:1});varT1 = F.call ({id:2}) () ();//id:1vart2 = f (). Call ({id:3}) ();//id:1varT3 = f () (). Call ({id:4});//id:1
The example above shows that the this of the arrow function cannot be changed, and conversely, if it is an ordinary anonymous function, it can be changed:
function foo () { return () = { function() { Console.log ( this. id); };};} var f1 = Foo.call ({id:1}) () ()//undefined; var f2 = foo (). Call ({id:1}) ()//undefined; var f3 = foo () (). Call ({id:1})//1
The first two this finally points to window, and the last point to {id:1}
Js--call, arrow functions/anonymous functions