Created
July 12, 2019 05:05
-
-
Save area73/ca5f4632f864cf468e9a63b36d675e85 to your computer and use it in GitHub Desktop.
#singleton, #singleton reinfircer
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
const _singletonEnforncer = Symbol('private'); | |
let _instance; | |
export default class EventHandler extends EventTarget { | |
static getInstance() { | |
return _instance || new EventHandler(_singletonEnforncer); | |
} | |
static throwSingletonError() { | |
throw new Error(` | |
Singleton Error instantiation: | |
EventHandler can only be instantiate by its static method EventHandler.getInstance() | |
`); | |
} | |
constructor(enfonrcer) { | |
enfonrcer !== _singletonEnforncer && EventHandler.throwSingletonError(); | |
super(); | |
_instance = this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment