// 定义一个动物类
function Animal (name) {
// 属性
this.name = name || 'Animal';
// 实例方法
this.sleep = function(){
console.log(this.name + '正在睡觉!');
}
}
// 原型方法
Animal.prototype.eat = function(food) {
console.log(this.name + '正在吃:' + food);
};
function Cat(name) {
// 调用Animal的构造函数
Animal.call(this);
this.name = name || 'Tom';
}
var cat = new Cat();
console.log(cat.name)
console.log(cat.sleep())
// 无法继承原型上的函数方法
console.log(cat.eat())