객체의 축약 표현
const title : 'codeit';
const birth : 2017;
const job : '강사';
const user = {
title : title,
birth : birth,
job : job,
}
const user = {
title,
birth,
job,
}
활용할 변수의 이름과 프로퍼티 네임이 똑같다면 생략 가능하다
function getFullName(){
return `${this.first} ${this.last}`;
}
const user = {
first: 'Tess',
last: 'Jang',
getFullName: getFullName,
};
const admin = {
first: 'Alex',
last: 'Kim',
getFullName,
};
console.log(user.getFullName());
console.log(admin.getFullName());
변수 이름이 메소드 이름과 같다 -> 생략
객체 내부에서 선언한다면 프로퍼티 네임과 function을 생략 가능
const user = {
first: 'Tess',
last: 'Jang',
getFullName: function getFullName(){
return `${this.first} ${this.last}`;
}
};
const user = {
first: 'Tess',
last: 'Jang',
getFullName(){
return `${this.first} ${this.last}`;
}
};
계산된 속성명 computed preperty name
: 표현식의 값을 프로퍼티 네임으로 쓸수있다
const user = {
[표현식] : 값;
}
['code' + 'it'] -> codeit 으로 받는다
[변수명] 위에서 선언된 변수 이름도 가능
'개발 공부 일지 > JavaScript' 카테고리의 다른 글
자바스크립트 - 구조분해 Destructing (0) | 2024.07.20 |
---|---|
자바스크립트 - 옵셔널 체이닝 ?. (0) | 2024.07.20 |
자바스크립트 - Spread 구문 syntax (0) | 2024.07.19 |
자바스크립트 - 조건을 다루는 표현식 (0) | 2024.07.19 |
자바스크립트 - 문장, 표현식 (0) | 2024.07.19 |