[JS] Enhanced Object Literals - 향상된 객체 리터럴

Brian·2021년 8월 25일
0

JavaScript

목록 보기
5/6
post-thumbnail

Enhanced Object Literals?

향상된 객체 리터럴이란 기존 JS 객체 정의 문법 작성 방식을 좀 더 간결하게 사용 할 수 있도록 객체 정의 방식을 개선한 문법이다.

#1. function 예약어 생략

기존 문법 방식
var dictionary = {
   lookup : function(){
      console.log('found something!!'); 
   }
}

dictionary.lookup(); // found something
ES6 문법
var dictionary = {
 lookup() {
    console.log('found something'); 
 }
}

dictionary.lookup(); // found something

#2. 속성명과 값이 같을 경우

기존 문법
var figures = 10;
var dictionary = {
  figures : figures, 
}
ES6
var figures = 10;
var dictionary = {
 figures,  
}
profile
Jiujitsu_coder

0개의 댓글