The question about js this

function foo(){
  setTimeout(()=>{
    console.log("is:",this.id);//42
  },100)
}
var id = 21;
foo.call({id:42})
The this of the function in

js is dynamic, depending on who calls it at run time, in which the this inside
foo points to an anonymous object
setTimeout is called globally
arrow function without this points to the this
of setTimeout, so why not 21 print result is 42?
ask God for a detailed explanation?

Feb.27,2021

because you used the arrow function
can be simply understood as: there is no this, inside the arrow function. If this, is used internally, it will save the defined this as part of the execution environment, and the saved this will be used during execution.

if you change the arrow function to function, the result will be different

  introduction to ES6  

Menu