Skip to content

Instantly share code, notes, and snippets.

@LauraBesnier
Forked from tdimnet/Singleton.js
Created October 11, 2021 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LauraBesnier/42b11f68b598f86c49720eda92e341cf to your computer and use it in GitHub Desktop.
Save LauraBesnier/42b11f68b598f86c49720eda92e341cf 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