Created
April 18, 2017 07:27
-
-
Save anonymous/5067959bccfec04c965bf9a68b9d043a to your computer and use it in GitHub Desktop.
7.5 Logger Array created by smillaraaq - https://repl.it/HHoC/3
This file contains hidden or 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 genLoggers(arrayLength){ | |
var resultArray=[]; | |
for(var i=0;i<arrayLength;i++){ | |
resultArray.push( | |
functionMaker(i) | |
); | |
} | |
function functionMaker(arrayIndex){ | |
return function(){ | |
console.log(arrayIndex); | |
}; | |
} | |
console.log(resultArray); | |
return resultArray; | |
} | |
var loggerArray = genLoggers(5); | |
loggerArray[0](); // 0 | |
loggerArray[4](); // 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment