Skip to content

Instantly share code, notes, and snippets.

@jackysee
Created September 30, 2013 09:18
Show Gist options
  • Save jackysee/6761282 to your computer and use it in GitHub Desktop.
Save jackysee/6761282 to your computer and use it in GitHub Desktop.
Code illustrate a classic closure problem
var arr = [1,2,3];
var out = [];
for(var i=0; i<arr.length; i++){
var item = arr[i];
out.push(function(){ alert(item); });
}
out.forEach(function(f){ f(); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment