If a constructor returns a value other than this, then in subclasses super() calls to that constructor should use the result as this in the subclass constructor.
I believe this is specified in 12.3.5.1, step 10 of SuperCall: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-super-keyword
Getting this behavior correct is going to be very important for supporting Custom Elements, which takes advantage of this to initialize browser-allocated elements with user-written constructors. See https://w3c.github.io/webcomponents/spec/custom/#htmlelement-constructor
Note, Babel 6 implements this correctly.
TypeScript Version:
1.8.9
Code
classFoo{x : number;constructor(){return{x: 1,};}}classBarextendsFoo{y : number;constructor(){super();this.y=2;}}leto=newBar();console.assert(o.x===1&&o.y===2);Expected behavior:
No assertion error
The constructor for Bar should compile to this:
varBar=(function(_super){__extends(Bar,_super);functionBar(){var_this=_super.call(this);_this.x=1;return_this;}returnBar;}(Foo));Actual behavior:
Assertion error
The constructor for Bar compiles to this:
varBar=(function(_super){__extends(Bar,_super);functionBar(){_super.call(this);this.x=1;}returnBar;}(Foo));
If a constructor returns a value other than
this, then in subclassessuper()calls to that constructor should use the result asthisin the subclass constructor.I believe this is specified in 12.3.5.1, step 10 of SuperCall: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-super-keyword
Getting this behavior correct is going to be very important for supporting Custom Elements, which takes advantage of this to initialize browser-allocated elements with user-written constructors. See https://w3c.github.io/webcomponents/spec/custom/#htmlelement-constructor
Note, Babel 6 implements this correctly.
TypeScript Version:
1.8.9
Code
Expected behavior:
No assertion error
The constructor for
Barshould compile to this:Actual behavior:
Assertion error
The constructor for Bar compiles to this: