// 父类
function Animal(name) {
this.name = name;
}
// 用prototype给父类加方法
Animal.prototype.eat = function() {
console.log(this.name + "要吃东西");
}
// 具体的子类,猫
function Cat(name,age,color){
// 用call方法将name传递给父类,记得call的第一个参数为this
Animal.call(this,name);
this.age = age;
this.color = color;
}
// 修改猫的构造方法的原型指向,new Animal()没有参数
Cat.prototype = new Animal();
// 新建具体的猫对象
var smallCat = new Cat("豆豆",12,"黑");
// 调用eat()方法
smallCat.eat();