1.原型链继承

让构造函数的原型对象等于另一个类型的实例,利用原型让一个引用类型继承另一个引用类型的属性和方法

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
View Code

相关文章:

  • 2022-02-20
  • 2021-09-20
  • 2022-12-23
  • 2021-07-20
  • 2022-01-20
  • 2021-11-20
  • 2022-01-03
  • 2022-02-09
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2021-06-10
  • 2021-12-02
  • 2021-12-30
  • 2022-01-26
  • 2022-02-28
相关资源
相似解决方案