Created
January 31, 2016 06:31
-
-
Save JeremyIglehart/5ed025233a13eb962923 to your computer and use it in GitHub Desktop.
Javascript Closure Fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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