Last active
January 30, 2018 10:18
-
-
Save haingdc/08b34278788dd66b09277ea8cd0d274b to your computer and use it in GitHub Desktop.
handle closure affect by iife step 1
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++) { | |
var y = year; // (2) | |
result.push(function() { return y; }); // (3) | |
} | |
console.log(result[1]()); // 4 (không phải 1) | |
console.log(result[3]()); // 4 (không phải 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment