Skip to content

Instantly share code, notes, and snippets.

@to4iki
Created August 31, 2014 16:39
Show Gist options
  • Save to4iki/cc7e6b8205e149474ade to your computer and use it in GitHub Desktop.
Save to4iki/cc7e6b8205e149474ade to your computer and use it in GitHub Desktop.
TypeScript - Singleton
class Singleton {
private static _instance:Singleton = null;
constructor() {
if(Singleton._instance){
throw new Error("must use the getInstance.");
}
Singleton._instance = this;
}
public static getInstance():Singleton {
if(Singleton._instance === null) {
Singleton._instance = new Singleton();
}
return Singleton._instance;
}
}
var singleton=Singleton.getInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment