proposal-decorators
proposal-decorators copied to clipboard
Constructor decorators
Previous discussion: https://github.com/tc39/proposal-decorators-previous/issues/23
Is this OK to leave for v2?
I'd would prefer to leave it for a follow on.
That said, I do like to delete MyClass.constructor somewhat often so it is tempting.
Hmm, we might be able to accommodate that particular case, by putting the constructor property in the elements list (as a "prototype method")... then a @noconstructor class decorator could remove that. Thoughts?
I think for now you could do that with a class decorator, since the class is the constructor function, no?
You mean with a finalizer which deletes the property? Yes, that is possible already, you are right.
@bmeck What does that do? Block the class from being instantiated?
With @noconstructor, access to an instance no longer automatically implies access to that instance's constructor. IOW, for @noconstructor class Foo, I can give you access to an instance of Foo while denying you access to the Foo constructor, i.e., to the class object.