The generated code that causes the error is
function Bar() {
Foo.call(this)
}
The apparent fix is to generate this instead:
function Bar() {
if (Foo.prototype.hasOwnProperty('constructor')) {
Foo.constructor.call(this)
} else {
Foo.call(this)
}
}
Well, the user may have manually created a function named ‘constructor’. Perhaps there is a foolproof way to check whether Foo was defined with the class syntax.