Skip to content

Instantly share code, notes, and snippets.

@MarcusHurney
Created February 2, 2017 07:00
Show Gist options
  • Save MarcusHurney/f70d9cd1ee7d57a4936bc6ea05529f6f to your computer and use it in GitHub Desktop.
Save MarcusHurney/f70d9cd1ee7d57a4936bc6ea05529f6f to your computer and use it in GitHub Desktop.
function buildFunction() {
var arr = [];
for (var i = 0; i < 3; i++) {
arr.push(
(function(j) {
return function() {
console.log(j);
}
})(i)
);
}
return arr;
}
var mynew = buildFunction();
mynew[0]();
mynew[1]();
mynew[2]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment