//es5
let Animal = function(type){
this.type = type
}
Animal.prototype.eat = function (){
console.log('eat food')
}
let dog = new Animal('dog')
let monkey = new Animal('monkey')
monkey.constructor.prototype.eat = function (){
console.log('eating')
}
dog.eat()
monkey.eat()
//es6
class Animal{
constructor(type){
this.type = type
}
eat(){
console.log('eating')
}
}
let dog = new Animal('dog')
let monkey = new Animal('monkey')
console.log(dog)
console.log(monkey)
dog.eat()
monkey.eat()
语法糖:语法不同,效果一样