Skip to content

Instantly share code, notes, and snippets.

@ewilazarus
Last active August 29, 2015 14:25
Show Gist options
  • Save ewilazarus/1c7053e63465354577c7 to your computer and use it in GitHub Desktop.
Save ewilazarus/1c7053e63465354577c7 to your computer and use it in GitHub Desktop.
function buildFunctions() {
var arr = [];
for (var i = 0; i < 3; i++) {
arr.push((function(j) {
return function() {
console.log(j);
};
}(i)));
}
return arr;
}
var fs = buildFunctions();
fs[0]();
fs[1]();
fs[2]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment