JS之继承

许多OO 语言都支持两种继承方式:接口继承(继承方法签名)和实现继承(继承实际的方法)。ECMAscript无法实现接口继承,只支持实际继承。

原生链:实现继承的主要方法。

基本思想:利用原型让一个引用类型继承另一个引用类型的属性和方法。

实例,构造函数,原型之间的关系

例:

function father(){  //父类的属性
    this.prototype = true ;
}
father.prototype.getfathervalue = function(){  //父类的方法
    return this.prototype;
};


function son(){   //子类的属性
    this.sonproperty = false ;
}
son.prototype = new father();   //从父类继承过来方法和属性
son.prototype.getsonvalue = function(){   //子类增加的方法,
        return this.sonproperty;
};


var b = new son();  //创建子类的实例
alert(b.getfathervalue());  //获得父类的方法
原文地址:https://www.cnblogs.com/cty97/p/6800860.html