Not forcing super in derived class's constructor?

Claude Pache claude.pache at
Mon May 11 17:08:33 UTC 2015

> Le 11 mai 2015 à 05:26, Glen Huang <curvedmark at> a écrit :
> No one care to comment? Hope I didn't mistake how super works.
>> On May 8, 2015, at 11:05 AM, Glen Huang <curvedmark at> wrote:
>> TLDR: If `this` is used without `super` (which should be statically analyzable), let it refer to Object.create( Otherwise, let super creates what it refers to.
>> I know the reason to force `super` in derived class's constructor is to make sure `this` refers to the exotic object the base class might allocate.
>> But I bet in real world, extending base classes who only create ordinary objects is more common than extending those create exotic objects. And forget to call super is going to be frequent mistake. In es5, when you extend a class like this
>> ```js
>> function Foo() {
>> }
>> Foo.prototype = Object.create(Bar.prototype);
>> ```
>> `this` refers to Object.create( So I wonder if we can keep this behavior, making things less surprising when people transit to es 2015?

Yes, in the course of refactoring your classes, you are indeed forced to transform your old clunky `` invocations into new shiny `super()` invocations, and it is IMHO a good thing. I don't see personally the point to support deprecated patterns in new syntactic forms.

But anyway, if refactoring your old classes is too difficult (for it might need more complicated changes that the aforementioned simple substitution), you are not obliged to: the old ES3/5 "classes" will continue to work, and will even be usable as superclass (in the `extends` clause) of new ES2015-classes.


More information about the es-discuss mailing list