Skip to content

Instantly share code, notes, and snippets.

@cdcd72
Last active November 17, 2020 09:07
Show Gist options
  • Save cdcd72/04636e52788653676dc0707a8f3da1f2 to your computer and use it in GitHub Desktop.
Save cdcd72/04636e52788653676dc0707a8f3da1f2 to your computer and use it in GitHub Desktop.
Singleton Pattern in TypeScript
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