Generator issue: exceptions while initializing arguments
Dmitry Soshnikov
dmitry.soshnikov at gmail.com
Mon Sep 10 17:19:29 PDT 2012
On Mon, Sep 10, 2012 at 2:47 PM, Jason Orendorff
<jason.orendorff at gmail.com>wrote:
> On Mon, Sep 10, 2012 at 2:59 PM, Tobie Langel <tobie.langel at gmail.com>
> wrote:
> > On Sep 10, 2012, at 9:48 PM, Jason Orendorff <jason.orendorff at gmail.com>
> wrote:
> >
> >> On Mon, Sep 10, 2012 at 12:50 PM, Kevin Smith <khs4473 at gmail.com>
> wrote:
> >>>>> function f(x=EXPR1, y=EXPR2) { BODY }
> >>>>> ===>
> >>>>> function f(x, y) {
> >>>>> if (x === void 0) x = EXPR1;
> >>>>> if (y === void 0) y = EXPR2;
> >>>>> BODY
> >>>>> }
> >>>
> >>> I'm not so sure - the desugaring above would mean that default
> expressions
> >>> would have visibility across curly-brace boundaries, which I find to be
> >>> quite surprising.
> >>
> >> It is surprising. It could even bite unwary programmers. But in what
> >> scope do you propose to evaluate default-param expressions?
> >
> > In their lexical scope.
>
> This isn't a complete answer. As it stands, the lexical scope of
> arguments is the same as the scope of everything else in the function
> body. Which leaves us with exactly what I was saying earlier.
>
>
I guess "lexical" here was meant the function definition scope, not the
parameters.
So in your later example:
var FOO = 2;
function bar(y = FOO + 3) {
return y;
}
The lexical scope of "y" is obviously the function body. However, the
lexical scope of "FOO" (from top-down viewing of the code) is the outer
scope, where "bar" function is defined.
So this should resolve to:
bar(); // 5
However, to avoid Python's issues with definition type bindings for
defaults, ES can eval every time at activation (in the bar.[[Scope]]
object, i.e. directly parent, but not the activation one).
FOO = 45;
bar(); // 48
Use cases like:
function bar(y = FOO + 3) {
var FOO = 10;
return y;
}
My look subtle, however, if again to accept lexical scope as the function
definition, then FOO again should be resolved in the bar.[[Scope]], not in
the bar's activation:
bar(); // still 48
P.S.: sorry, didn't have a change to read the whole discussion, apologies
if it was noted already.
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120910/9289a00e/attachment.html>
More information about the es-discuss
mailing list