function Animal(name,age){
this,name = name;
this.age = age;
}
//原型中添加方法
Animal.prototype.eat = function(){
console.log("动物吃东西");
this.play();
};
Animal.prototype.play = function(){
console.log("玩球");
this.sleep();
};
Animal.prototype.sleep = function(){
console.log("睡觉了");
};
//实例化对象
var dog = new Animal("小明",20);
dog.eat();
网友评论