Created
March 20, 2023 13:08
-
-
Save andresgcarmona/9fc7177dbf5a18220fc2a7aaf5ae2cba to your computer and use it in GitHub Desktop.
Singleton Typescript
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 class Singleton { | |
// Define your props here | |
private _express: Application = express(); | |
private static _instance: Singleton; | |
constructor() { | |
if (Singleton._instance) { | |
return Singleton._instance; | |
} | |
// You don't have an instance, so continue | |
// Remember, to set the _instance property | |
Singleton._instance = this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment