Generator issue: exceptions while initializing arguments
Dmitry Soshnikov
dmitry.soshnikov at gmail.com
Mon Sep 10 18:07:22 PDT 2012
On Mon, Sep 10, 2012 at 5:55 PM, Dmitry Soshnikov <
dmitry.soshnikov at gmail.com> wrote:
>
> But not this one:
>
> var FOO = 42;
> function bar(x, y = FOO + y) { var y = 10; } // Error .. ?
>
>
Typo, mean if there is no such parameter, but only the local var:
var FOO = 42;
function bar(x, y = FOO + z) { var z = 10; } // Error .. ?
P.S.: Though, it still seems that the parent-only scope fits better since
avoids complexities. Otherwise, we'll get yet another interesting quiz
questions like this one:
var x = 10;
(function foo() {
console.log(x); // undefined?
var x = 20;
})();
(which is funny, though). Similar will come for this outer FOO and inner
FOO in different run-time circumstances, i.e. unpredictable behavior --
first the outer FOO exists, then it's removed, and at the second call it
resolves already to the inner frame. This will definitely be banned as a
bad practice (having FOO inside and outside), so to avoid this -- outer
only scope is more preferable.
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120910/7a508db8/attachment.html>
More information about the es-discuss
mailing list