Generator issue: exceptions while initializing arguments

Tobie Langel tobie.langel at gmail.com
Tue Sep 11 01:39:27 PDT 2012


On Tue, Sep 11, 2012 at 10:33 AM, Brendan Eich <brendan at mozilla.com> 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.

I agree that's terrible and should absolutely be avoided. Sorry for
bringing it up.

--tobie


More information about the es-discuss mailing list