Last active
June 8, 2017 14:43
-
-
Save AlexandrBukhtatyy/24e9464572cd5be4d0bb9f14a07a7a63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(start) { | |
var count = start; | |
var timer; | |
var timerDelay = 1000; | |
return { | |
increment: function(){ | |
count++; | |
}, | |
start: function(){ | |
if(timer == undefined){ | |
timer = setInterval(function(){ | |
this.increment(); | |
console.log('count:' + count); | |
}.bind(this),timerDelay); | |
} | |
}, | |
stop: function(){ | |
clearInterval(timer); | |
timer = undefined; | |
}, | |
get: function() { | |
return count; | |
} | |
} | |
} | |
var c = Counter(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment