[Referring to Allen’s slides: http://wiki.ecmascript.org/lib/exe/fetch.php?id=meetings%3Ameeting_jan_29_2013&cache=cache&media=meetings:subclassing_builtins.pdf ]
Is this really true? I can see four ways of invoking a constructor function C: 1. As a function: C(...) 2. Via `new`: new C(...) 3. Via `call`: C.call(this, ...) 4. Via `super`, in a sub-instance, as a method (similar to #3): super.constructor(...) C[@@create] is only invoked during #2 (by the `new` operator). Thus, the constructor’s role is always: set up an uninitialized instance. You could add a check against an instance being initialized twice, but that doesn’t seem to be what the slides are about. The slides mention one use case: What if you want to have a function Foo that can be either called as a function or as a constructor? You can’t detect the difference if Foo is inside a namespace object. That is, you want to distinguish #1 from all others, but #1 could happen to a namespaced C. Observations: – Does recognizing whether `this` is initialized really help here? Isn’t it more about checking whether `this` is an instance of C? – I’ve always considered this to be more of an anti-pattern for non-builtin code. Thus, it seems useful to support a check, but only so that namespaced constructors can avoid accidentally polluting the namespace object. – Won’t namespace objects go away with modules? Thanks! Axel -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss