Created
June 4, 2014 12:51
-
-
Save rustyJ4ck/4dc84d83560cea478132 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
(function(){ | |
var _stop = false; | |
var id; | |
var i = 0; | |
function start() { | |
id = setInterval(task, 2000); | |
} | |
function stop() { | |
_stop = true; | |
console.log('stopped') | |
} | |
function task() { | |
if (_stop) { | |
clearInterval(id); | |
return false; | |
} | |
console.log(i++); | |
// do job | |
if (i > 2) { | |
stop(); | |
} | |
} | |
start(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment