Last active
December 10, 2018 03:08
-
-
Save fczbkk/746a7516e210c2e39dc0fc184b4a0646 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
/** | |
* Creates a simple counter that starts at 0 and is raised by 1 on each bump. | |
* @return {{getCurrentValue: (function(): number), bump: (function(): number)}} | |
* @example | |
* const myCounter = createCounter() | |
* myCounter.getCurrentValue() // 0 | |
* myCounter.bump() // 1 | |
* myCounter.bump() // 2 | |
* myCounter.getCurrentValue() // 2 | |
*/ | |
function createCounter () { | |
let currentValue = 0 | |
return { | |
/** | |
* Returns current value of the counter. | |
* @return {number} | |
*/ | |
getCurrentValue: () => currentValue, | |
/** | |
* Bumps the value of counter and returns new value. | |
* @return {number} | |
*/ | |
bump: () => ++currentValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment