Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on How do JavaScript closures work?. Parent comment
That's easy enough to test. var y=20;
function foo(x) { var tmp = 3; var y = 20; return function (y) { alert(x + y + (++tmp)); }
var bar = foo(2); // bar is now a closure.
bar(10);
This makes no difference. The alert runs once, and displays 16.
There are no comments on this comment yet.
That's easy enough to test. var y=20;
}var bar = foo(2); // bar is now a closure.
bar(10);
This makes no difference. The alert runs once, and displays 16.