Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created January 18, 2011 15:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoward/784629 to your computer and use it in GitHub Desktop.
Save ahoward/784629 to your computer and use it in GitHub Desktop.
capturing deferred state with a closure
// a solution to http://blog.abhiomkar.in/2010/07/03/javascript-code-challenge-by-dropbox-team/
//
var countdown = function(num){
for (var i = 0; i <= num; i += 1) {
(function(i){ setTimeout(function(){ alert(num - i); }, i * 1000); })(i);
}
}
countdown(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment