Javascriptに関する質問です。
パターンや表現については、重複する質問があります。jsオブジェクトを宣言して取得する最善の方法は何ですか? (模様)
以下の3つを使用してオブジェクトを取得できます。 結果オブジェクトは同じです。
重いjavascript Webアプリケーションを使用すると、どのパターンが最適ですか?順番に
、
1.オブジェクトリテラルの場合
2.閉鎖ケース
3.新しいケースとanonymouse機能
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;}
}