//動(dòng)物的構(gòu)造函數(shù)
function Animal(name,weight) {
this.name = name;
this.weight = weight;
}
//動(dòng)物的原型方法
Animal.prototype.eat = function() {
console.log("只會(huì)吃");
};
//狗的構(gòu)造函數(shù)
function Dog(color) {
this.color = color;
}
Dog.prototype = new Animal("旺財(cái)","30kg");
Dog.prototype.bitePerson = function () {
console.log("咬死你");
};
//哈士奇
function ErHa(sex) {
this.sex = sex;
}
ErHa.prototype = new Dog("黑白色");
ErHa.prototype.playHost = function () {
console.log("和主人玩");
};
var erHa = new ErHa("雄性");
console.log(erHa.name,erHa.weight,erHa.color);
erHa.eat();
erHa.bitePerson();
erHa.playHost();
上面代碼的原型鏈