// 定义一个动物类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(){}// 通过对猫类的原型集成动物的类Cat.prototype = new Animal();Cat.prototype.name = 'cat';// 创建猫的实例var cat = new Cat()// 此时cat也会具有animal的属性
// (二)构造函数继承function Cat(name){Animal.call(this);this.name = name || 'Tom';}
