-
-
Save AliceWonderland/916279c6f1b7fd9b39be04f012233bb4 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