repeated parameter names and default values

Jason Orendorff jason.orendorff at gmail.com
Thu Sep 27 10:09:58 PDT 2012


On Thu, Sep 27, 2012 at 11:19 AM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
>    function f(a, b=a, a=3, c=a) {
>       return a+" "+b+" "+c
>    }
>    console.log(f(1));
>
> Based upon the conclusions about argument binding at the recent TC39 meeting this will display:
>   "3 1 3"

Not having been at the meeting, I had a little trouble coming up with
a desugaring where this worked. Is this the idea?

    function f(a, b, a, c) {
        var %args = a copy of arguments;
        a = %args[0];
        b = %args[1] === void 0 ? a : %args[1];
        a = %args[2] === void 0 ? 3 : %args[2];
        c = %args[3] === void 0 ? a : %args[3];
        return a+" "+b+" "+c;
    }

(Of course I understand it won't be specified in terms of desugaring
but through changes to 10.5.3, "Function Declaration Instantiation").

For what it’s worth, I’m with David and Oliver: by all means, just
make that a SyntaxError.

-j


More information about the es-discuss mailing list