Skip to content

Instantly share code, notes, and snippets.

@AlexandrBukhtatyy
Last active June 8, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexandrBukhtatyy/24e9464572cd5be4d0bb9f14a07a7a63 to your computer and use it in GitHub Desktop.
Save AlexandrBukhtatyy/24e9464572cd5be4d0bb9f14a07a7a63 to your computer and use it in GitHub Desktop.
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