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"
If we have an object:
const object = {
arrowFunc: () => this,
};
and then we call:
console.log(object.arrowFunc()); // Window {window: Window, self: Window, document: document, name: '', location: Location, …}
We get the window object, why is the arrow function not returning the object itself as this
?
If the arrow function retains the this
value of the enclosing lexical scope, then shouldn't that be the object where function itself is defined i.e object
?