Skip to content

Instantly share code, notes, and snippets.

@matthias11-21
Created September 29, 2015 06:29
Show Gist options
  • Save matthias11-21/c2aba0785c9c7f0abedd to your computer and use it in GitHub Desktop.
Save matthias11-21/c2aba0785c9c7f0abedd to your computer and use it in GitHub Desktop.
Fun with JavaScript scoping
$ 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