Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You need to use `.bind()` to set the context, or switch to using arrow functions. Both methods are sub-optimal. `@autobind` solves that.


Why is

   @autobind
   foo() {
     // ...
   }
more optimal than

   foo = () => {
     // ...
   }

?


Please, Nothing is ever _more optimal_.


Class properties solve that too, with less magic IMO.


Decorators are awesome! Stop this blasphemy.


Bad example, checkout mobx or core-decorators.

@computed get value() { return this.a + 1; } @readonly bar = 5;


The use of decorators in Anguar 2/4 is also very well done, IMHO. They allow your class to focus on its business logic, rather than the minute details of how Angular expects it to interact with the rest of Angular.

There's a reason all the most common languages have them, concealing complexity is a way to reduce cognitive overload and therefore, bugs.




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

Search: