Created
January 27, 2018 18:42
-
-
Save matthieu-D/6cc04db706d8b63ab5db286230aa24ae to your computer and use it in GitHub Desktop.
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 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