js如何实现继承
发布网友
发布时间:2022-04-27 06:32
我来回答
共1个回答
热心网友
时间:2022-04-22 11:28
原型链
function SuperType() {
this.property = true;
}
SuperType.prototype.getSuperValue = function() {
return this.property;
}
function subType() {
this.property = false;
}
//继承了SuperType
SubType.prototype = new SuperType();
SubType.prototype.getSubValue = function (){
return this.property;
}
var instance = new SubType();
console.log(instance.getSuperValue());//true