Skip to content

Instantly share code, notes, and snippets.

@JeremyIglehart
Created January 31, 2016 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremyIglehart/5ed025233a13eb962923 to your computer and use it in GitHub Desktop.
Save JeremyIglehart/5ed025233a13eb962923 to your computer and use it in GitHub Desktop.
Javascript Closure Fun
function buildFunctions() {
var arr = [];
for (i = 0; i < 3; i++) {
arr.push(
function(number) {
number = number || 0;
i = i + number;
console.log(i);
}
)
}
return arr;
}
var fs = buildFunctions();
fs[0]();
fs[1](5);
fs[2]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment