Created
January 16, 2021 19:55
-
-
Save mxdi9i7/051e50b75049f04c797ad9aefdc8b059 to your computer and use it in GitHub Desktop.
ES6 Function based OOP design
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
function Counter(startingCount) { | |
this.startingCount = startingCount; | |
this.count = this.startingCount; | |
this.increment = () => { | |
this.count = this.count + 1; | |
}; | |
this.decrement = () => { | |
this.count = this.count - 1; | |
}; | |
this.reset = () => { | |
this.count = this.startingCount; | |
}; | |
this.getCount = () => { | |
return this.count; | |
}; | |
} | |
const my_counter = new Counter(100); | |
my_counter.increment(); | |
my_counter.increment(); | |
my_counter.increment(); | |
my_counter.decrement(); | |
console.log(my_counter.getCount()); | |
my_counter.reset(); | |
console.log(my_counter.getCount()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment