Rest parameter syntax

Felix Böhm esdiscuss at
Tue Jun 12 11:56:36 PDT 2012

Another nice place for this syntax would be destructuring: If you want to
get the last elements of an array, you might want to simply use

[...arr, foo, bar] = arr;

I really like that syntax. And in the end, that's what

function(...arr, foo, bar){…}

is doing. The difference to

bar = arr.pop();
foo = arr.pop();

is that foo is preferred when only one value is available. Written in the
JS of today, you'll need to write

if(arr.length > 0){
  if(arr.length !== 1){
    bar = arr.pop();
  foo = arr.pop();

And it'll get more complicated with every added variable.

It's quite interesting that Herby used that syntax with the only feedback
being that he can't use destructuring at that place :D

@Rick: I don't get your point. Of course, undefined should be treated as
any other value, everything else would be confusing. Or what were
you referring to?

As I've already written, parameters after rest can't have default values,
which (partially) fixes the issue of optional parameters.

2012/6/12 T.J. Crowder <tj at>

> On 12 June 2012 18:14, Brendan Eich <brendan at> wrote:
>> Red guy still on your shoulder :-P.
> I think you're seeing things. ;-) But seriously, I don't really have a
> horse in this race (at all, I was just exploring the concept -- seems
> that's already been done), happy to leave it at that.
> -- T.J.
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list