new instantiation design alternatives

Allen Wirfs-Brock allen at
Wed Sep 17 10:55:45 PDT 2014

On Sep 17, 2014, at 6:39 AM, Kevin Smith wrote:

>     constructor(x, y) {
>         if (new^)
>             this = new super(x);
>         else
>             super.constructor(x);
>         this.y = y;
>     }
> The point here is that the purpose of the constructor method is not only allocation, but also (and primarily) initialisation.
> Yes - you are right.  And I think we can safely assume that users will refuse to write such boilerplate.  I'll have to consider things for a bit before replying to the larger point.

Most users most of the time don't need that boiler plate.  In the unusual cases where they need it, this design forces them to be explicit about their intent.  I think that's a good thing.

Also note there are other initialization patterns that a user or framework might choose to use. We talk about one of these (bottom up initialization) quite a bit at the last TC39 meeting. The "Patterns for Alternative Construction Frameworks sections of my Gists explored some of these patterns. ( and ).  Note that in some cases, the cleanest thing is to factor the actual initialization code into a separate method. 


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

More information about the es-discuss mailing list