jayphelps / core-decorators

Library of stage-0 JavaScript decorators (aka ES2016/ES7 decorators but not accurate) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more. Popular with React/Angular, but is framework agnostic.
MIT License
4.52k stars 263 forks source link

Autobind decorator #138

Open barmaglot92 opened 7 years ago

barmaglot92 commented 7 years ago

Hi, why you didn`t use .bind for autobind decorator. So why you use WeekMap and so complicated realization?

jayphelps commented 6 years ago

It does indeed use .bind if it's available.

Creating a truly universal autobind decorator is harder than one thinks. There are numerous edge cases that have been found over the years, one of which is when you autobind a method that calls the same method on the super prototype and that method was also had used autobind

I try to include brief descriptions in the online comments about why things are done

// Autobound method calling super.sameMethod() which is also autobound and so on.

jayphelps commented 6 years ago

More insight into the super.sameMethod() problem needing WeakMap #20 and #21