Rest parameter syntax

Herby Vojčík herby at mailbox.sk
Tue Jun 12 09:03:13 PDT 2012



T.J. Crowder wrote:
> On 12 June 2012 16:42, Herby Vojčík <herby at mailbox.sk
> <mailto:herby at mailbox.sk>> wrote:
>
>
>     But I understand there are problems. First, what with optional
>     params after ...rest. And the second, how to parse it when foo(1, 2)
>     called?
>
>
> I would think with
>
> function foo(a, b, ...others, c) {
> }
>
> then given
>
> foo(1, 2);
>
> ...within foo a is 1, b is 2, others is empty, and c is undefined. E.g.,
> args prior to the restargs get priority over args after rest args. This
> is consistent with
>
> foo(1);
>
> ...where within foo a is 1, b is undefined, others is empty, and c is
> undefined.
>
> It does seem as though it can be deterministic, and pretty easy to
> explain. Which isn't necessarily an endorsement, just identifying that

function foo (a, b, ...rest, c, d) { ... }
foo(1, 2, 3)

What here?

Yes, [1, 2, [], 3, undefined] is probably the most logical one. But then 
d is not the last one (yes, it is only last one when there is at least 
four of them).

> this particular issue doesn't immediately seem like a roadblock.
>
> -- T.J.


More information about the es-discuss mailing list