firstNameメソッドとlastNameメソッドの現在の値を表示する方法が間違っていることは理解できません。今のところ私はjone.Nameとjone.lastにエラーがあります。なぜなら、それらは不定になるからです。コンストラクタのObject.definePropertyの取得で「未定義」
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);
2番目の解決策は私が必要とするものですが、今私はdefinePropertyで間違っていることを理解しています。 –