firstName 및 lastName 메서드의 현재 값을 표시하는 방법을 잘못 이해합니다. 왜냐하면 지금은 존에 오류가 있습니다. 이름과 존."undefined"in Object.defineProperty in Constructor
function User(fullName) {
this.fullName = fullName.split(' ');
Object.defineProperty(this, 'firstName', {
get: function() {
this.firstName = this.fullName[0];
return this.firstName;
}
});
Object.defineProperty(this, 'lastName', {
get: function() {
this.lastName = this.fullName[1];
return this.lastName;
}
});
}
var jone= new User("Jone Coven");
console.log(jone.fullName);
console.log(jone.firstName);
console.log(jone.lastName);
두 번째 솔루션은 필자가 필요로하는 것입니다. 이제 defineProperty에서 잘못된 것을 이해합니다. –