Skip to content

Instantly share code, notes, and snippets.

@alexmasyukov
Created January 31, 2018 03:16
Show Gist options
  • Save alexmasyukov/c702956e7c39225cd1204209180473cc to your computer and use it in GitHub Desktop.
Save alexmasyukov/c702956e7c39225cd1204209180473cc to your computer and use it in GitHub Desktop.
Get_Set.jsx
// Get, Set через деструктуризацию
class User {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
set fullName(newValue) {
[this.firstName, this.lastName] = newValue.split(' ');
}
}
let user = new User('Vasya', 'Pupkov');
console.log(user.fullName);
user.fullName = 'Alex Masyukov';
console.log(user.fullName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment