객체 리터럴 안에서의 함수

박경준·2022년 11월 1일
0
let person = {
  name: ['Bob', 'Smith'],
  age: 32,
  gender: 'male',
  interests: ['music', 'skiing'],
  bio () {
    // 이런식으로 객체 리터럴 안에서 key값 따로 없이, function 선언 따로 없이 함수를 선언하고 사용할 수 있음.
    console.log(`${this.name[0]} ${this.name[1]} is ${this.age} years old`);
  },
};

const func = (item) => {
  return person[item]()
}
console.log(func('bio'))
// Bob Smith is 32 years old

vue options에 있는 훅들도 이런 형태였지 않았을까...?

profile
빠굥

0개의 댓글