Rest parameter syntax

Herby Vojčík herby at mailbox.sk
Tue Jun 12 08:42:46 PDT 2012



Rick Waldron wrote:
>
>
> On Tue, Jun 12, 2012 at 10:38 AM, Felix Böhm <esdiscuss at feedic.com
> <mailto:esdiscuss at feedic.com>> wrote:
>
>     Per definition, rest parameters always need to be at the end of a
>     FormalParameterList. I was wondering if this limitation could be liftet.
>
>
> Consider:
>
>
> function foo( a, b, ...others, c ) {
>    return [ a, b, others, c ];
> }
>
>
> foo( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
>
>
>    a  b  others
> [ 1, 2, [ 3, 4, 5, 6, 7, 8, 9 ] ]
>
>
> How do you resolve where to stop claiming arguments as items in the rest
> param "others"?

[ 1, 2, [ 3, 4, 5, 6, 7, 8 ] ]
As I understand Felix's idea, it's that the parameters after ...rest eat 
up the last ones. Using last (or last few) params is the often used (not 
that I like it) pattern - node.js is full of it since callback is always 
last.

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?

> Rick

Herby


More information about the es-discuss mailing list