Skip to content

Instantly share code, notes, and snippets.

@khamiltonuk
Created February 21, 2014 06:36
Show Gist options
  • Select an option

  • Save khamiltonuk/9129813 to your computer and use it in GitHub Desktop.

Select an option

Save khamiltonuk/9129813 to your computer and use it in GitHub Desktop.
Time based repetition
//Alternative to setInterval
//Set interval will run the function doStuff() every 100ms regardless if doStuff has finished.
setInterval(function(){
doStuff();
},100);
//Alternatively you can use argements.callee after doStuff(); which will is wrapped in a self invoking anyonomous self invoking function
(function(){
doStuff();
setTimeout(arguments.callee,100);
})();
// arguments.callee calls the parent function, support is wide spreed with no plans of removing but in older browsers for arguments.callee is unreliable
// arguments.callee has been removed from ES5 strict mode
//You can get around this by declaring the function with a name and calling it within the setTimeout
(function doStuff() {
// Statements
setTimeout(doStuff, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment