Last active
March 9, 2018 15:40
-
-
Save zburgermeiszter/2cbe02999ecb65a3062d4b58d74f39f7 to your computer and use it in GitHub Desktop.
Revisions
-
zburgermeiszter revised this gist
Mar 9, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // https://stackoverflow.com/a/36978360 class Singleton { private static _instance: Singleton; -
zburgermeiszter created this gist
Mar 8, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ class Singleton { private static _instance: Singleton; private constructor() { console.log("Instantiated"); } public static getInstance(): Singleton { console.log("getInstance()"); return this._instance || (this._instance = new this()); } } const i1 = Singleton.getInstance(); const i2 = Singleton.getInstance(); const i3 = Singleton.getInstance(); console.log(i1 === i2); console.log(i2 === i3); console.log(i1 === i3);