DEV Community

Discussion on: ES6 Arrow Function Syntax Explained Simply

Collapse
 
lsimonis profile image
Lukas Simonis • Edited

It's not quite accurate to say "Arrow functions do not have access to this."

Rather, they inherit the this object of the calling scope:

class C {
  x = 10;
  o = {
    x: 20,
    functionGetX: function () { return this.x; },
    arrowGetX: () => this.x,
  };
}
(new C).o.functionGetX(); // 20
(new C).o.arrowGetX();    // 10
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dan_v profile image
Dan V

Thanks for the clarification @lsimonis . For now, I've updated the article to say they "do not have their own this". :)