Skip to content

Instantly share code, notes, and snippets.

@matthieu-D
Created January 27, 2018 18:42
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 matthieu-D/6cc04db706d8b63ab5db286230aa24ae to your computer and use it in GitHub Desktop.
Save matthieu-D/6cc04db706d8b63ab5db286230aa24ae to your computer and use it in GitHub Desktop.
export default class CounterSingleton {
counter = 0;
private static instance : CounterSingleton;
static getInstance() {
if (!CounterSingleton.instance) {
CounterSingleton.instance = new CounterSingleton();
}
return CounterSingleton.instance;
}
add() {
this.counter++;
}
show() {
console.log(this.counter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment