If you set constructor
back to its original value, i.e. Child
, and establish inheritance properly:
function Child() {
Parent.call(this);
}
Child.prototype = Object.create(Parent.prototype, {
constructor: {value: Child}
});
// or, instead of passing a property descriptor
Child.prototype.constructor = Child;
// (but this makes `constructor` enumerable)
a clone method can be as simple as
Parent.prototype.clone = function() {
return new this.constructor();
};
See also Classical inheritance with Object.create
.