Skip to content

Instantly share code, notes, and snippets.

@pvamshi
Created May 3, 2015 14:52
Show Gist options
  • Save pvamshi/1af1713e59acbea284b8 to your computer and use it in GitHub Desktop.
Save pvamshi/1af1713e59acbea284b8 to your computer and use it in GitHub Desktop.
Closures fail
var myAlerts = [];
for (var i = 0; i < 5; i++) {
myAlerts.push(
function inner() {
console.log(i);
}
);
}
myAlerts[0]();
myAlerts[1]();
myAlerts[2]();
myAlerts[3]();
myAlerts[4]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment