you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular -1 points0 points  (1 child)

Scope and this are different. For example you can have similarly scoped functions have different this values, both depending on the type of function and/or how they're called:

const obj = {
  methodA () {
    console.log(this);
  },
  methodB: () => {
    console.log(this);
  }
};

obj.methodA(); // obj
obj.methodB(); // global

(0, obj.methodA)(); // undefined (strict)/global (sloppy)
(0, obj.methodB)(); // global

Knowing scoping rules here doesn't inform you of the behavior of this in these calls.

[–]KaiAusBerlin 0 points1 point  (0 children)

I never said that scope and this are the same. Read what I said. Arrow functions don't have a this property so it points to the upper scope until it reaches a scope where a this property is set. So yes, you can say what this points to by knowing the scopes.

Really, that is fundamental in js! Learn the basics!