function game(){ var prop = 8; var a = { get prop() { return prop; } }; Abort(a.prop);}
function game(){ var other = 8; var a = { get prop() { return other; } }; Abort(a.prop);}
function testPropertyScoping() { var prop = 8, o = {get prop() { return prop; }}; return o.prop;}testPropertyScoping(); // 8 in both Chrome 30 (Canary) and Firefox 22 (Stable).function testPropertyScoping2() { var o = {get prop() { return prop; }}; return o.prop;}testPropertyScoping2(); // Both throw ReferenceError: prop is not defined.
a variable already in scope is not overwritten when a function declaration is made with the same name.
...wow, that's... not what I'd expect at all. That means if you have a named, recursive function and move it into a scope where a local variable by the same name exists, the entire function would break. From a language-design point of view, that's just asking for trouble.
function outer() { var inner = 5, fn = function inner() { return inner; }; return fn;}outer()(); // function inner() { return inner; }
Quote from: Lord English on July 25, 2013, 02:14:14 am...wow, that's... not what I'd expect at all. That means if you have a named, recursive function and move it into a scope where a local variable by the same name exists, the entire function would break. From a language-design point of view, that's just asking for trouble.JavaScript as a language is just asking for trouble.