Not forcing super in derived class's constructor?

Glen Huang curvedmark at gmail.com
Mon May 11 03:26:59 UTC 2015


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 gmail.com> wrote:
> 
> TLDR: If `this` is used without `super` (which should be statically analyzable), let it refer to Object.create(new.target.prototype). 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() {
> 	Bar.call(this)
> }
> Foo.prototype = Object.create(Bar.prototype);
> ```
> 
> `this` refers to Object.create(new.target.prototype). So I wonder if we can keep this behavior, making things less surprising when people transit to es 2015?



More information about the es-discuss mailing list