Ошибка в геттере
Не вижу причину ошибки missing ) after argument list, не понимаю,
в чем проблема, заранее спасибо. function User(fullName) { this.fullName = fullName; Object.defineProperties(this, 'fullName', get: function(){ //!!! return this.firstName + ' ' + this.lastName; }, set: function(value){ var names = value.split(' '); this.firstName = names[0]; this.lastName = names[1]; } ) } |
function User(fullName) { this.fullName = fullName; Object.defineProperties(this, 'fullName', { get: function() { return this.firstName + ' ' + this.lastName; }, set: function(value) { var names = value.split(' '); this.firstName = names[0]; this.lastName = names[1]; } }) } |
Цитата:
defineProperties принимает ведь только 2 аргумента думаю, тут еще вместо defineProperties должно быть defineProperty |
полагаю, этот код более правильный
function User(fullName) { this.fullName = fullName; Object.defineProperty(this, 'fullName', { get: function() { return this.firstName + ' ' + this.lastName; }, set: function(value) { var names = value.split(' '); this.firstName = names[0]; this.lastName = names[1]; } }) } |
Цитата:
upd. вот так будет правильно с defineProperties: function User(fullName) { this.fullName = fullName; Object.defineProperties(this, { fullName: { get: function() { return this.firstName + ' ' + this.lastName; }, set: function(value) { var names = value.split(' '); this.firstName = names[0]; this.lastName = names[1]; } } }); } |
Часовой пояс GMT +3, время: 01:33. |