58 ms·
Decorators don't work like annotations. They're functions applied to the function (or class) under them. As such, I find them much more direct and logical (and
by BulgarianIdiot 5y ago
Decorators don't work like annotations. They're functions applied to the function (or class) under them. As such, I find them much more direct and logical (and debuggable).
Can you use them poorly? Sure, but this applies to anything.
I.e. how is a decorator like this:
@dec
class Foo {...}
Different than this?
let Foo = dec(
class Foo {...}
);
It seems the same to me (mostly). The above has a better syntax.
- chii 5y agodecorators are better because of scoping imho.
- tobr 5y ago> They're functions applied to the function (or class) under them. Now that’s wrong. Decorators don’t work on functions, just methods. Which is ironic if you think about it, because if you program with functions you already have the tools you need to compose things, no need to invent some syntax sugar like this. For some reason object oriented programmers don’t seem to think like that. They want a special name and special syntax for everything.
- saurik 5y agoYeah: in a very real sense the "original sin" here was introducing (nay: forcing) class syntax to JavaScript, a language which at its core doesn't even naturally use/model classes (as it was designed around prototypes); all of this other complexity is the language falling downhill in an attempt to merely regain functionality for this new syntax that was previously trivial when you simply assigned "methods" directly to your prototype with the = operator (and so making it obvious where you would add a normal function call to functionally compose behaviors instead of needing a "decorator").