寄生组合式继承

function inheritPrototype(Cat, Animal) {
    Cat.prototype = Object.create(Animal.prototype);
    Cat.prototype.constructor = Cat;
} 

 

function inheritPrototype(subType, superType) {
    var prototype = Object(superType.prototype);  //建立对象
    prototype.constructor = subType;              //加强对象
    subType.prototype = prototype;                //指定对象
}
相关文章
相关标签/搜索