Created
September 12, 2023 09:13
-
-
Save alejoar/677c40104ee569a9000e5af0d92d103a to your computer and use it in GitHub Desktop.
Singleton
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 Singleton { | |
constructor() { | |
if (Singleton._instance) { | |
return Singleton._instance; | |
} | |
Singleton._instance = this; | |
} | |
someFunction = () => { | |
console.log("I am a singleton"); | |
} | |
} | |
const s1 = new Singleton(); | |
const s2 = new Singleton(); | |
assert(s1 === s2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment