Last active
November 17, 2020 09:07
-
-
Save cdcd72/04636e52788653676dc0707a8f3da1f2 to your computer and use it in GitHub Desktop.
Singleton Pattern in TypeScript
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 { | |
private static instance: Singleton; | |
private constructor() { } | |
/** | |
* 取得實例 | |
* @returns Singleton | |
*/ | |
public static getInstance(): Singleton { | |
if(!Singleton.instance) | |
Singleton.instance = new Singleton(); | |
return Singleton.instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment