Skip to content

Instantly share code, notes, and snippets.

@Grsmto
Created January 7, 2013 20:41
Show Gist options
  • Save Grsmto/4478209 to your computer and use it in GitHub Desktop.
Save Grsmto/4478209 to your computer and use it in GitHub Desktop.
Javascript - "arguments.callee" technique : this value points to the anonymous function in which the code is executing.
var todo = items.concat(); //create a clone of the original array
setTimeout(function(){
//get next item in the array and process it
process(todo.shift());
//if there's more items to process, create another timer
if(todo.length > 0){
setTimeout(arguments.callee, 25); // arguments.callee = anonymous function where the code is executing
} else {
callback(items);
}
}, 25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment