Skip to content

Instantly share code, notes, and snippets.

@tdimnet
Created August 4, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdimnet/2d14a1b110972b449c81213b86db7cff to your computer and use it in GitHub Desktop.
Save tdimnet/2d14a1b110972b449c81213b86db7cff to your computer and use it in GitHub Desktop.
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