寄生组合式继承

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;                //指定对象
}

 

posted @ 2019-01-31 17:56  井凉一一  阅读(136)  评论(0编辑  收藏  举报