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

Axel Rauschmayer axel at
Sun Mar 17 17:29:18 PDT 2013


> awbjs IOW, I’d write the check: if (typeof this !== "object" || !($fooBrand in this) || this[$fooBrand]) /*CAAF*/
> perhaps:  if ( this ===null || typeof this !== "object" ||  this[$fooBrand]!==undefined) /*CAAF*/
> if depends upon how the @@create method chooses to use as an "uninitialized" marker.  Setting the brand property value to undefined works in many cases.

The `this[$fooBrand]!==undefined` still looks wrong (it would be true for an uninitialized instance). How about the following?

    if ( this ===null || typeof this !== "object" ||  this[$fooBrand] !== false) /*CAAF*/

Then the last Or operand is true if either the instance has already been initialized or if `this` is an object that does not have a property whose key is $fooBrand (e.g. a namespace object). Interestingly, this expression is not the same as `! this[$fooBrand]`.

> @awbjs On slide 22, wouldn’t you first call @@create (⇒this[$fooBrand]=false) and then execute the “constructor initialization case”?
> Are you talking about for the CAAF case?   If you want factory function behavior I would code the then clause as: return new Foo();
> or perhaps: return new this.constructor()
> You could put in explicit calls to @@create but it probably better to let new do that part.
> In the Rev 14 draft, most of the built-in constructors that have CAAF behavior use some variation of this pattern expressed in pseudo code.
> I think the built-in support in slides 23 and 24 would be best, but TC39 doesn't really understand it yet. 

I’d prefer a dynamic solution, but don’t see one.

Dr. Axel Rauschmayer
axel at


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

More information about the es-discuss mailing list