Last active
August 25, 2016 07:08
-
-
Save frontdevops/bcff6333b33bab8fb565bb824e8037c5 to your computer and use it in GitHub Desktop.
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 { | |
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