Created
January 30, 2018 10:20
-
-
Save haingdc/75f34cf23d9c8a10e2d1cab4e9cadf19 to your computer and use it in GitHub Desktop.
handle closure affect by iife step 2
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
var result = []; | |
for(var year = 0; year < 5; year++) { | |
(function() { | |
var y = year; | |
result.push(function() { return y; }); | |
})(); | |
} | |
console.log(result[1]()); // 1 | |
console.log(result[3]()); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment