Skip to content

Instantly share code, notes, and snippets.

@alejoar
Created September 12, 2023 09:13
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 alejoar/677c40104ee569a9000e5af0d92d103a to your computer and use it in GitHub Desktop.
Save alejoar/677c40104ee569a9000e5af0d92d103a to your computer and use it in GitHub Desktop.
Singleton
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