-
-
Save WesleySmits/281f1443ff0657237e8641c880327738 to your computer and use it in GitHub Desktop.
SingletonExample - Class
This file contains hidden or 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
export default class SingletonExample { | |
static #instance: SingletonExample; | |
public static getInstance(): SingletonExample { | |
if (!this.#instance) { | |
this.#instance = new SingletonExample(); | |
} | |
return this.#instance; | |
} | |
private constructor() {} | |
} | |
// How to retrieve the instance | |
const instance = SingletonExample.getInstance(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment