Generator issue: exceptions while initializing arguments

Dmitry Soshnikov dmitry.soshnikov at
Tue Sep 11 12:03:23 PDT 2012

On Tue, Sep 11, 2012 at 11:37 AM, Dmitry Soshnikov <
dmitry.soshnikov at> wrote:

> On Tue, Sep 11, 2012 at 1:33 AM, Brendan Eich <brendan at> wrote:
>> If you really want the Pythonic default parameter rules (evaluation in
>> definition context) then you need to address the bad case Jason showed:
>>   function foo(arg = []) {
>>     arg.push('strange');
>>     return arg;
>>   }
>>   foo(); // ['strange']
>>   foo(); // ['strange', 'strange']
>> This is a side channel and a big footgun. ES6 default parameters as
>> proposed avoid it.
> Sure, and as I mentioned in my first message -- ES may eval defaults every
> time at activation, not only once as Python does. But -- still in the outer
> scope (in the foo.[[Scope]] in your example).
> function foo(arg = <expression>) { ... }
> evaluates the <expression> every time at activation as:
> 1. If expression is a literal value, create a *new* value corresponding to
> literal. Assign to the parameter. Return.

OK, now I see that this defers to the activation time *only*, which
probably doesn't make much sense in evaluation in only parent scope. Sorry
for confusion, yes, in this case evaluation including activation frame fits

And I also see now Allen's example with generators, which, if to accept
desugaring you noted (with if (== void 0) then assign) may be an issue if
creation of the generator should not trigger the activation until the
"next" call.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list