-
Object Literal 방식FrontEnd/Javascript 2022. 5. 11. 12:09728x90
- 자바스크립트는 객체를 생성하고 프로퍼티를 지정하는 객체 리터럴(object literal) 문법을 제공한다.
// 내장 객체 생성 var car = new Object(); car.color = "white"; car.price = "1000만원"; car.getinfo = function() { document("색상: ", this.color); document("가격: ", this.price); } console.log(car);
위의 코드를 Object Literal 방식으로 바꾸면
// Object Literal 방식 var car = { "color": "white", "price": "1000만원", "getinfo": function() { document("색상: ", this.color); document("가격: ", this.price); } }
var car = {} 는 객체를 생성하는것
'FrontEnd > Javascript' 카테고리의 다른 글
함수(function) (0) 2022.05.11 선택문(switch 문) (0) 2022.05.11 삼항조건 연산자를 이용한 질의응답 (0) 2022.05.11 삼항조건 연산자 (0) 2022.05.11 논리 연산자 (0) 2022.05.11