Closed
Description
The following should log true
but logs false
instead:
class Foo {}
class Bar extends Foo {}
console.log(Object.getPrototypeOf(Bar) === Foo);
This is due to how the __extends helper is implemented. It generates this:
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
An example of a correctly functioning extends implementation can be found in the 6to5 compiler. Here is their implementation:
var _extends = function (child, parent) {
child.prototype = Object.create(parent.prototype, {
constructor: {
value: child,
enumerable: false,
writable: true,
configurable: true
}
});
child.__proto__ = parent;
};