proposal-decorators icon indicating copy to clipboard operation
proposal-decorators copied to clipboard

Constructor decorators

Open littledan opened this issue 7 years ago • 6 comments

Previous discussion: https://github.com/tc39/proposal-decorators-previous/issues/23

Is this OK to leave for v2?

littledan avatar Feb 10 '18 23:02 littledan

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.

bmeck avatar Feb 28 '18 18:02 bmeck

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?

littledan avatar Mar 01 '18 17:03 littledan

I think for now you could do that with a class decorator, since the class is the constructor function, no?

ljharb avatar Mar 01 '18 17:03 ljharb

You mean with a finalizer which deletes the property? Yes, that is possible already, you are right.

littledan avatar Mar 01 '18 18:03 littledan

@bmeck What does that do? Block the class from being instantiated?

jsg2021 avatar Mar 01 '18 20:03 jsg2021

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.

erights avatar Mar 01 '18 23:03 erights