JS关于继承的一個例子

2019-03-27  本文已影响0人  ?尛孞

function SuperType(){

this.property = true;

} //Object.prototype == 

SuperType.prototype.getSuperValue = function(){

return this.property;

};

function SubType(){

this.subproperty = false;

}

//继承了 SuperType

SubType.prototype = new SuperType();

SubType.prototype.getSubValue = function (){

return this.subproperty;

};

var instance = new SubType();

alert(instance.getSuperValue());

SubType.prototype = new SuperType();

console.log(SubType.prototype.__proto__ == SuperType.prototype); //true

上一篇 下一篇

猜你喜欢

热点阅读