Created
September 29, 2015 06:29
-
-
Save matthias11-21/c2aba0785c9c7f0abedd to your computer and use it in GitHub Desktop.
Fun with JavaScript scoping
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
$ cat foo.js | |
function foo() { | |
function bar(bllll1) { | |
return function() { return blllll; } | |
} | |
var list = []; | |
for (var i=0; i<10; i++) { | |
var blllll = "Fuck yeah! (" + i + ")"; | |
list.push(bar(blllll)); | |
} | |
list.forEach(function(f) { console.log(f()); }); | |
} | |
foo(); | |
$ node foo.js | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
Fuck yeah! (9) | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment