寄生組合式繼承

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;                //指定對象
}
相關文章
相關標籤/搜索