I'm trying to understand how the arrow function passed to setTimeout
, remembers the value of this
from the previous execution context. I know that the this
value is looked up using lexical scoping rules when executing arrow functions. Does that mean the arrow function closes over variables and the this keyword?
var obj = {
name: 'TestName',
func: function() {
console.log(this)
setTimeout(() => console.log(this), 1000)
}
}
obj.func() //{name: "TestName", func: ƒ}