The arrow function in ES6 as an object attribute, the pointing problem of this

when I read the book introduction to ES6, I introduced the arrow function this

. The immobilization of
this is not because there is a mechanism for binding this inside the arrow function, but because the arrow function does not have its own this, at all, so the internal this is the this of the outer code block.

there are also clouds on the Internet

The this binding of the
arrow function looks at the object under which the function of this is defined, and this points to the object to which it is bound
const Person = {
        "sayHello": () => {console.log(this)}
            };
      Person.sayHello();

Why does the this here point to window? Why not the this. of the Person object of the external code block

Mar.28,2021

Update

const func = () => {
  console.log(this);
};

const Person = {
  hello: func,
};

Person.hello();

so naturally it is window , and the place where the function is declared is window .

Menu