Skip to content

Instantly share code, notes, and snippets.

@area73
Created July 12, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save area73/ca5f4632f864cf468e9a63b36d675e85 to your computer and use it in GitHub Desktop.
Save area73/ca5f4632f864cf468e9a63b36d675e85 to your computer and use it in GitHub Desktop.
#singleton, #singleton reinfircer
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