As written before:
function foo(a, b, ...others, c){ … }
behaves the same as
function foo(a, b, ...others){
var c = others.pop();
}
When the number of parameters following the rest parameter is greater or
equal the number of passed arguments, the rest parameter is an empty array
and the parameters get assigned in order until there are no more arguments.
Unassigned parameters default to undefined.
When the number of arguments is greater than the number of parameters
following the rest parameter, then the first(argument-number -
parameter-number) arguments are passed as the rest parameter.
2012/6/12 Herby Vojčík <[email protected]>
>
>
> T.J. Crowder wrote:
>
>> On 12 June 2012 16:42, Herby Vojčík <[email protected]
>> <mailto:[email protected]>> 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.
>>
> ______________________________**_________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss