Created
August 2, 2019 17:58
-
-
Save Weiyuan-Lane/b903408115e473961a36ff48506e792a to your computer and use it in GitHub Desktop.
Creating a singleton using a constructor
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
export default class StoreSingleton { | |
static _singleton = null | |
constructor() { | |
if (StoreSingleton._singleton === null) { | |
StoreSingleton._singleton = this | |
} | |
return StoreSingleton._singleton | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment