Skip to content

Instantly share code, notes, and snippets.

@viebel
Created August 22, 2012 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viebel/3427266 to your computer and use it in GitHub Desktop.
Save viebel/3427266 to your computer and use it in GitHub Desktop.
javascript: function defined inside a loop
var numbers = [1,2,3];
for (var i = 0, n = numbers.length; i<n; i++) {
var num = numbers[i];
setTimeout(function() {
console.log(num);
}, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment