-
-
Save liujingyu/6e77f93982a92d8c3bd9b86325de6a6c to your computer and use it in GitHub Desktop.
javascript闭包作用域
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
for (var i = 0; i < 5; i++) { | |
setTimeout(function () { | |
console.log(i); | |
}, 5); | |
} |
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
for (var i = 0; i < 5; i++) { | |
(function (idx) { | |
setTimeout(function () { | |
console.log(idx); | |
}, 5); | |
})(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment