如何创造一只会叫并且会吃饭的狗子
方法1.
function animal() {
this.eat = "我会吃";
}
function dog() {
this.bark = "我会叫";
}
dog.prototype = new animal();
var dog = new dog();
console.log(dog.bark);
console.log(dog.eat);
方法2:
function animal() {
this.eat = "我会吃";
}
function dog() {
this.bark = "我会叫";
animal.call(this);
}
var dog = new dog();
console.log(dog.bark);
console.log(dog.eat);