Skip to content

Instantly share code, notes, and snippets.

@frontdevops
Last active August 25, 2016 07:08
Show Gist options
  • Save frontdevops/bcff6333b33bab8fb565bb824e8037c5 to your computer and use it in GitHub Desktop.
Save frontdevops/bcff6333b33bab8fb565bb824e8037c5 to your computer and use it in GitHub Desktop.
class Singleton {
protected static _instance :Singleton;
protected foo :number = 123;
constructor() {
if (Singleton._instance) {
throw new Error("Instantiation failed: "+
"use Singleton.getInstance() instead of new.");
}
Singleton._instance = this;
}
public static getInstance() :Singleton {
if (Singleton._instance) {
return Singleton._instance;
}
return Singleton._instance = new Singleton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment