0
JavaScript를 연구 중이고 속성 인 객체를 생성하려고합니다. 그러나, character.strength를 콘솔에 로깅 할 때 나는 실행되지 않고 함수를 얻는다. 올바른 구문은 무엇입니까?함수를 객체 속성으로 사용하기
console.log(character.strength());
당신은 또한 게터 속성을 구현할 수 있습니다 :
{ get strength() { return this.name.length.toString() + this.age; } }
을 ... 당신이 그랬던 것처럼 값에 액세스
name: "Jack",
age: 19,
strength: function() {
character.name.length() + name.age;
}
};
console.log(character.strength);
'var character = {'... – Bergi
'.length'라는 줄을 포함한 전체 코드를 보여줄 수 있습니다. 당신이 부를 수있는 방법이 아니라 숫자입니다! – Bergi