when reading teacher Ruan Yifeng"s ES6 tutorial, in the arrow function chapter, in the section on this pointing, there is such an example
function foo() {
setTimeout( () => {
console.log("this.id:",this.id);
},100);
}
var id = 21;
foo({ id: 42}); // 21
foo.call({ id: 42}); // 42
at this time, the output id is 21, which is
pointing to window.so I"m a little confused about this example, which should be used to illustrate that the this direction here is changed by the arrow function, but as far as I understand it, it feels like it is changed by the call function.
because I have never been particularly clear about where this points to me, I think there is a misunderstanding of where I should be. I have tried to check the relevant knowledge points, but I still can"t figure it out. I hope someone can explain this example 0.0
.