var foo = '1',
bar = '2';
console.log(foo, bar, window.foo);
(function(foo){
console.log(foo, bar);
})(bar);
I have two trivial questions regarding the code above:
Why window.fooundefined? Are all global variables bound to the window object?
Why foo ===2 inside closure? I know that convey the original baralias foo, which is equal to 2, but outside the scope foostill 1. And, as far as I know, the source foocan be accessed from within the closing device. Is "new foo" a priority because it is passed as an argument to IIFE?
http://jsfiddle.net/GbeDX/
Johan source
share