Hacker News new | past | comments | ask | show | jobs | submit login

Seriously. It feels like an entire area of JavaScript I pretty much never wade into anymore.



Why not?


Untechnically speaking: Arrow functions preserve the `this` in their declaration point, whereas regular functions change `this` if they're called as methods.

    class Foo {
      thisCouldBeAnything() {return this}
      thisIsDefinitelyFoo = () => this
    }
    
    new Foo().thisCouldBeAnything.call('use me')
    // 'use me'
    
    new Foo().thisIsDefinitelyFoo.call('unused')
    // Foo
Since the intention is often to keep `this` to refer to the class, people have been binding every single method in the class constructor, but this is no longer necessary thanks to arrow functions.


New features were added to the language that make this sort of stuff unecessary.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: