Skip to content

Instantly share code, notes, and snippets.

@ifucolo
Created August 31, 2017 05:01
Show Gist options
  • Save ifucolo/6980bde6b648c74acdb2dd96ea350cd0 to your computer and use it in GitHub Desktop.
Save ifucolo/6980bde6b648c74acdb2dd96ea350cd0 to your computer and use it in GitHub Desktop.
var counter, quantity = 10;
var list = [];
for(counter = 0; counter < quantity; counter++){
var object = {};
object.onClick = (function(counter) {
return function() {
alert(counter);
}
})(counter)
list.push(object);
}
list[1].onClick()
list[5].onClick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment