Created
November 5, 2018 16:38
-
-
Save ortense/1077f2e04081c863e57032d2b12213e9 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
const createTimer = () => { | |
let paused = true | |
let counter = 0 | |
let interval | |
return { | |
play() { | |
paused = false | |
interval = setInterval(() => counter += 1, 1000) | |
}, | |
pause() { | |
paused = true | |
clearInterval(interval) | |
}, | |
toggle() { | |
paused ? this.play() : this.pause() | |
paused = !paused | |
}, | |
get paused() { | |
return paused | |
}, | |
get current(){ | |
return counter | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment