Skip to content

Instantly share code, notes, and snippets.

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