原型链继承
实现原理 : 重写子类原型对象,代之以一个新类型的实例。
function SuperType(){
this.property = true;
}
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()); // true
继承后的实例和构造函数和原型之间的关系图如下:
缺点
发表回复