자바 스크립트 관련 질문.
패턴 또는 표현식에 대해 중복 된 질문 일 수 있습니다.js 객체를 선언하고 가져 오는 가장 좋은 방법은 무엇입니까? (무늬)
아래의 세 가지를 사용하여 개체를 얻을 수 있습니다. 결과 개체가 동일하게 작동합니다.
무거운 자바 스크립트 웹 응용 프로그램을 사용할 때 가장 좋은 패턴은 무엇입니까? 순서
, 새로운 사건
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;}
}