Created
August 20, 2013 16:50
-
-
Save nsbingham/6284049 to your computer and use it in GitHub Desktop.
Example module with singletons
This file contains hidden or 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
module ConfigManager { | |
export class Browser {} | |
export class Config { | |
name:String; | |
} | |
export class BrowserManager { | |
private static _instance:BrowserManager = null; | |
public config:Config; | |
public browser:Browser; | |
constructor() { | |
if(BrowserManager._instance){ | |
throw new Error("Error: Instantiation failed: Use BrowserManager.getInstance() instead of new."); | |
} | |
BrowserManager._instance = this; | |
} | |
public static getInstance():BrowserManager | |
{ | |
if(BrowserManager._instance === null) { | |
BrowserManager._instance = new BrowserManager(); | |
BrowserManager._instance.config = new Config(); | |
BrowserManager._instance.browser = new Browser(); | |
} | |
return BrowserManager._instance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment