//行爲都是一樣的,沒有必要去重複創建.
//我們可以存在一個共享庫裏面,共享庫裏面內存和地址都是一樣的。無論任何一個對象訪問,都是訪問一個內存地址.
//使用prototype只會創建一次.
function Dog(option){
this.init(option);
}
Dog.prototype.init=function(option){//init初始化數據
this.name=option.name;
this.age=option.age;
this.dogFricends=option.dogFricends;
}
Dog.prototype.eat=function(someThing){//行爲
console.log(this.name+'吃'+someThing);
}
Dog.prototype.run=function(someWhere){//行爲
console.log(this.name+'跑'+someWhere);
}
var smallDog=new Dog({name:'小花',age:11,dogFricends:['球球','嘎嘎']});//小狗
var bigDog=new Dog({name:'大花',age:18,dogFricends:['球球','嘎嘎','hh']})//大狗
console.log(smallDog.eat===bigDog.eat)//true