-
-
Save LauraBesnier/42b11f68b598f86c49720eda92e341cf to your computer and use it in GitHub Desktop.
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
class User { | |
constructor(firstName, lastName) { | |
if (User.exists) { | |
return User.instance | |
} | |
this._firstName = firstName | |
this._lastName = lastName | |
User.exists = true | |
User.instance = this | |
return this | |
} | |
get firstName() { | |
return this._firstName | |
} | |
get lastName() { | |
return this._lastName | |
} | |
get user() { | |
return { | |
firstName: this._firstName, | |
lastName: this._lastName | |
} | |
} | |
} | |
const FirstUser = new User('thomas', 'd') | |
const SecondUser = new User('alexandra', 'c') | |
console.log(FirstUser) | |
console.log(SecondUser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment