<分区>
Possible Duplicate:
Should I use prototype or not?
Closures in auto executing functions vs objects
所以,我正在用 JavaScript 创建一个对象,有两种方法可以实现:
function car(){
this.engineOn = false;
this.startEngine = function(){
this.engineOn = true;
}
}
或
function car(){
this.engineOn = false;
}
car.prototype.startEngine = function(){
this.engineOn = true;
}
最好的方法是什么?这两种方法有什么好处或坏处吗?