Skip to content

Instantly share code, notes, and snippets.

@teodorpatras
Created November 26, 2016 11:04
Show Gist options
  • Select an option

  • Save teodorpatras/088a756586269820f4987e3e48af8102 to your computer and use it in GitHub Desktop.

Select an option

Save teodorpatras/088a756586269820f4987e3e48af8102 to your computer and use it in GitHub Desktop.
function Timer(onTick) {
var self = this,
interval,
startTime,
count
self.start = function() {
count = 0
startTime = (new Date()).toISOString()
interval = window.setInterval(function() {
count++
onTick(count)
}, 1000)
}
self.stop = function() {
count = 0;
clearInterval(interval)
return {
start: startTime,
end: (new Date()).toISOString()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment