Created
January 31, 2018 03:16
-
-
Save alexmasyukov/c702956e7c39225cd1204209180473cc to your computer and use it in GitHub Desktop.
Get_Set.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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