The pointing problem of Arrow function this

var o = {
    a:11,
    b: () => {
        console.log("this is", this);
    }
}

o.b();

clipboard.png

Why does this point to window?

Mar.10,2021
The this object in the body of the
 () => { }thisthis

arrow function () = >
function is the object in which it is defined, not the object in which it is used. The direction of the
this object is variable, but in the arrow function, it is fixed.


the arrow function this points to the superior, o defines that all this points to window


without the arrow function this refers to o this object, o actually the this in the window.o, arrow function will indicate that the outer this, is the this, under window, of course it is window.

Menu