-
Notifications
You must be signed in to change notification settings - Fork 126
Description
Continuing from https://phabricator.babeljs.io/T2005 and #41 (I don't recommend reading the latter issue though).
Currently property decorators for both classes and objects operate on a descriptor pseudo-property "initializer", based on this document. In my opinion this is over-complicating and also misleading in the case of class properties, because:
-
This descriptor property is not used anywhere else; it won't even be found in the class fields and static properties spec - initializers for the class fields are kept as simple functions (not descriptors).
-
It differentiates between the properties and the methods, e.g.:
{ @foo bar() {} }
and
{ @foo bar: function() {} }
foohas to handle two different versions of decorators for these cases. -
The "initializer" property exists because of class properties, which are sugar for initializing instance properties in the constructor. I think it is misleading that the decorators are applied only once, whereas the initializers are called each time the class is instantiated.
In the first referred issue @wycats says:
It's a critical constraint that decorators can run only once when the class is built and not add additional runtime cost unless the decorator chooses to add cost (by wrapping, for example). You can achieve both goals via initializer functions, but deferring the decorator until instantiation adds unavoidable cost.
So there is a performance concern. But still, for me the least surprise is more important. If I wanted to write really performant code, I wouldn't use decorators at all - they make life easier only for the programmer and not for the machine that will be executing the code.
@isiahmeadows @jayphelps @jeffmo @loganfsmyth @lukescott Could you please weigh in on this?