function vie(){
var speed = 100
return {
getSpeed: () => speed,
speedUp:function(){
speed+=10
}
}
}
console.log(vie().getSpeed())
vie().speedUp()
console.log(vie().getSpeed())
var car = vie()
car.speedUp()
car.speedUp()
console.log(car.getSpeed())
原型
function Viechel() {
this.speed = 100;
}
Viechel.prototype.speedUp = function() {
this.speed += 10;
}
var car = new Viechel();