Created
August 31, 2014 16:39
-
-
Save to4iki/cc7e6b8205e149474ade to your computer and use it in GitHub Desktop.
TypeScript - Singleton
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 { | |
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