<script>
function myPlay(){
console.log("打王者榮耀");
}
function Person(name,age){
this.name=name;
this.age=age;
this.eat=function(){
console.log("喜歡喫土豆");
}
this.myPlay=myPlay;
}
Person.prototype.myHabit=function(){
console.log('喜歡讀論語');
}
Person.prototype={
constructor:Person,
height:"180cm",
myWork:function(){
console.log('喜歡程序員');
},
mySport:function(){
console.log('喜歡跑步');
}
}
var per1 = new Person('小白',20);
var per2 =new Person('小黑',25);
console.log(per1.eat == per2.eat);
console.log(per1.myPlay == per2.myPlay);
console.log(per1.myHabit == per2.myHabit);
console.log(per1.myWork == per2.myWork);
console.log(per1.mySport == per2.mySport);
</script>
function Animal(name,age){
this.name=name;
this.age=age;
this.eat=function(){
console.log(‘喫食物’);
this.sleep();
};
this.sleep=function(){
console.log('睡覺’);
this.eat();
}
}
Animal.prototype.play=function(){
console.log('玩骨頭’);
this.walk();
}
Animal.prototype.walk=function(){
console.log('喜歡滾泥巴’);
this.sleep();
}
var dog=new Animal('來福',2);
dog.eat();
dog.play();