Javascript的问题。
关于模式或表达,可能是重复的问题。声明和获取js对象的最佳方式是什么? (图案)
您可以在下面使用其中的三个获取对象。 结果对象工作原理相同。
当您使用沉重的JavaScript web应用程序时,哪种模式最好?
为了,
1.对象文字的情况下
2.关闭情况下
3.新情况
function car = {
name: 'Q5',
type:'SUV',
wheels:4,
door:2,
score: 0,
getWheel: function(){return this.wheels;},
getDoor: function(){return this.door;},
setScore: function(score){ this.score = score;}
}
var car = (function(){
var name = 'Q5',
type ='SUV',
wheels = 4,
door = 2,
score = 0;
return {
getWheel: function(){return wheels},
getDoor: function(){return door},
setScore: function(_score){ score = _score;}
}
})();
var car = new function(){
var name = 'Q5',
type ='SUV',
wheels = 4,
door = 2,
score = 0;
this.getWheel = function(){return wheels}
this.getDoor = function(){return door}
this.setScore = function(_score){ score = _score;}
}