let user = {
name: "John",
surname: "Smith",
get fullName() {
return `${this.name} ${this.surname}`;
},
set fullName(value) {
[this.name, this.surname] = value.split(" ");
}
};
// set fullName is executed with the given value.
user.fullName = "Alice Cooper";
alert(user.name); // Alice
alert(user.surname); // Cooper
-
Если не нужно брать объединение свойств в виде fullName или установка имени и фамилии через fullName - то тогда не нужен.– Сергей Мишин7 июл 2019 в 20:58
Добавить комментарий
|
1 ответ
alert(user.fullName );
user.fullName = "Alice Cooper";