repeated parameter names and default values
Allen Wirfs-Brock
allen at wirfs-brock.com
Thu Sep 27 10:42:07 PDT 2012
On Sep 27, 2012, at 10:09 AM, Jason Orendorff wrote:
> 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;
> }
Yes, essentially that plus presumably appropriate length checks on %args.
Also, I assume by "arguments" you mean the actual passed argument vector rather than the arguments object.
Allen
More information about the es-discuss
mailing list