Constructors need to be able to recognize uninitalized instances(?)

Axel Rauschmayer axel at
Sun Mar 17 09:20:44 PDT 2013

[Referring to Allen’s slides: ]

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`:, ...)
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?



Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list