new instantiation design alternatives

Claude Pache claude.pache at gmail.com
Tue Sep 16 06:52:41 PDT 2014


Le 15 sept. 2014 à 04:47, Domenic Denicola <domenic at domenicdenicola.com> a écrit :

> 
> I think I'd most be in favor of a third option that implicitly adds `this = Object.create(new^.prototype)` if no `this`-assignment is present. That way, the superclass constructor is never implicitly called, which is kind of what you would expect.

FWIW, it is quite near of what is done in PHP, which many web developers are familiar with:

* if you want to call the super (a.k.a. parent) constructor, you call it. If you don't call it, it won't be called. (It is the evident path to me, apparently it is not for some people used to other languages?);
* you are not constrained to call the super constructor at the beginning, (or at the end, or whatever);
* in any case, you get inheritance right. (It is a obligatory in PHP, and it should be the default in JS if you don't do something special.)

The main semantic difference is that the instance (`this`) is available in PHP before you call the super constructor.

—Claude


More information about the es-discuss mailing list