Created
November 16, 2018 09:25
-
-
Save DimitryDushkin/783776232e84ef5425fcb4de2b923de7 to your computer and use it in GitHub Desktop.
TypeScript singleton (swift style)
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
export default class SomeSingleton { | |
private static privateShared: Api; | |
public static get shared(): Api { | |
if (!SomeSingleton.privateShared) { | |
SomeSingleton.privateShared = new SomeSingleton(); | |
} | |
return SomeSingleton.privateShared; | |
} | |
public foo() {} | |
} | |
// Using | |
import SomeSingleton from './some-singleton'; | |
SomeSingleton.shared.foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment