4 ms·
> Also decorators are only for classes? Why does that make any sense? The generally thought is that you technically only need them for classes (and really, onl
by shados 8y ago
> Also decorators are only for classes? Why does that make any sense?
The generally thought is that you technically only need them for classes (and really, only for class members and properties). For anything else you can just use a higher order function. Not as pretty, but JS decorator arent about syntax sugar, they're about filling one of the bazillion gaps in the language that opens when you introduce a class keyword.
Of course, the spec for decorator has been thrown away and started over once already (so basically no one using typescript/angular/mobx/whatever with decorators are actually spec compliant these days), and the new spec has been in limbo for years. Decorators aren't part of JS at all right now.