//动物的构造函数
function Animal(name,weight) {
this.name = name;
this.weight = weight;
}
//动物的原型方法
Animal.prototype.eat = function() {
console.log("只会吃");
};
//狗的构造函数
function Dog(color) {
this.color = color;
}
Dog.prototype = new Animal("旺财","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();
上面代码的原型链
网友评论