new instantiation design alternatives

Allen Wirfs-Brock allen at wirfs-brock.com
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. (https://gist.github.com/allenwb/5160d109e33db8253b62#patterns-for-alternative-construction-framework and https://gist.github.com/allenwb/53927e46b31564168a1d#constructor-called-as-function-patterns ).  Note that in some cases, the cleanest thing is to factor the actual initialization code into a separate method. 

Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140917/58b72b03/attachment.html>


More information about the es-discuss mailing list