I would like to know if expressions of the form new super.SomeProperty
are valid in JavaScript.
This question arose while working with code that behaves inconsistently across browsers like the example in the snippet below.
class Test {
test() {
return new super.constructor;
}
}
console.log((new Test).test());
This prints an empty object in Firefox and Edge but throws a ReferenceError
in Chrome and a SyntaxError
in Safari. The error can be easily circumvented putting parentheses around super.constructor
or using a variable, so it's not a real limitation, rather a matter of curiosity about the language itself. I checked the spec but couldn't find anything implying that an error should be thrown in this case, so it's likely that I'm missing something.