This code:
class Super {
/**
* @nocollapse
*/
static method() {
return 'foo';
}
}
class Sub extends Super {}
console.log(Sub.method()); // should log 'foo'
console.log(Sub.hasOwnProperty('method')); // should log 'false' because Sub.method is inherited
Is lowered to ES5 that is essentially:
function Super() {}
Super.method = function() { return 'foo' }
function Sub() {}
Sub.prototype = Object.create(Super.prototype);
Object.setPrototypeOf(Sub, Super);
Sub.method = Super.method;
console.log(Sub.method()); // logs 'foo', correctly
console.log(Sub.hasOwnProperty('method')); // logs 'true', incorrectly
The Sub.method = Super.method; line is unnecessary, because Object.setPrototypeOf(Sub, Super); has already ensured that Sub.method would work correctly, and it also causes Sub.method to be an ownproperty of Sub, which diverges from the original code's semantics.
This code:
Is lowered to ES5 that is essentially:
The
Sub.method = Super.method;line is unnecessary, becauseObject.setPrototypeOf(Sub, Super);has already ensured thatSub.methodwould work correctly, and it also causesSub.methodto be an ownproperty ofSub, which diverges from the original code's semantics.