MDN: In arrow functions, this retains the value of the enclosing lexical context's this. In global code, it will be set to the global object:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
I wrote this code:
const outerObj = {
lemon:5,
obj:{
egg:5,
apple: () => {console.log(this)}
}
}
outerObj.obj.apple()
Why global object printed? my arrow function doesn't have her own this, so she looks for her outer scope, and it should be the "this" of obj, so I expect to see { egg: 5, apple: [Function: apple] }, what I missed?