Created
July 2, 2014 07:13
-
-
Save Chris927/64faacebb7a0cfcda56c to your computer and use it in GitHub Desktop.
Nice Little Javascript Scope Challenge
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
| // credit: http://rzrsharp.net/2011/06/27/what-does-coffeescripts-do-do.html | |
| var closures = []; | |
| function createClosures() { | |
| for (var i = 0; i < 5; i++) { | |
| closures[i] = function() { | |
| console.log("i=" + i); | |
| } | |
| } | |
| } | |
| function run() { | |
| for (var i = 0; i < 5; i++) { | |
| closures[i](); | |
| } | |
| } | |
| createClosures(); | |
| run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment