Skip to content
On this page

Object Literal

On this page

Object Literal

Object Literal이란 객체를 Literal 표기법 (initializer 표기법)으로 생성하는 방법이다.

const object1 = {
a: 'foo',
b: 42,
c: {}
}
console.log(object1.a); // "foo"

자바스크립트에서는 객체 리터럴에서 Function Literal로 함수까지 정의할 수 있다.

var newobj = {
var1: true,
var2: "very interesting",
method1: function () {
alert(this.var1)
},
method2: function () {
alert(this.var2)
}
};
newobj.method1();
newobj.method2();

LINKS TO THIS PAGE