compat-table
compat-table copied to clipboard
Test for super() returning object other than `this`
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.
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
Here's an example that works in correct ES2015 implementation, and fails in some others:
class Foo {
constructor() {
return {
x: 1,
};
}
}
class Bar extends Foo {
constructor() {
super();
this.y = 2;
}
}
let o = new Bar();
console.assert(o.x === 1 && y === 2);
console.assert(o.x === 1 && o.y === 2);