只有实现继承-----继承实际的方法
原型链
每一个构造函数都有一个原型对象,原型对象包含一个指向构造函数的指针,实例都包含一个指向原型对象的内部指针
原型对象等于另一个类型的实例 则原型对象→ 另一个原型→ 另一个构造函数
function SuperType(){
this.property = true;//构造函数里的实例属性
}
SuperType.prototype.getSuperValue = function(){
return this.property;
};
function SubType(){
this.subproperty = false;
}
//继承SuperType
SubType.property = new SuperType();
SubType.property.getSubValue = function(){
return this.subProperty;
};
var instance = new SubType();
alert(instance.getSuperValue);//true
instance 的constructor 指向 SuperType
子类覆盖超类的方法----------给原型添加方法的代码要放到替换原型的语句之后
不能使用对象字面量创建原型的方法
原型链 引用类型 会 共享 解决方法
function SubType(){
SuperType.call(this);
}