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;}
}