Javascript 之原型链
1 min read#Javascript
function SuperType() {
this.property = true;
}
SuperType.prototype.getSuperValue = function() {
return this.property;
}
function SubType() {
this.subproperty = false;
}
// 修改 SubType 的原型,重新指向 SuperType
SubType.prototype = new SuperType();
SubType.prototype.getSubValue = function() {
return this.subproperty;
}
let instance = new SubType();
console.log(instance.getSuperValue()) // true
console.log(instance.getSubValue()) // false
