An update on rest operator ?

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Aug 2 10:54:15 UTC 2017


Previous disussions:

https://esdiscuss.org/topic/strawman-complete-array-and-object-destructuring

https://esdiscuss.org/topic/rest-parameters

-- T.J. Crowder

On Wed, Aug 2, 2017 at 10:58 AM, Siegfried Ehret <siegfried at ehret.me> wrote:

> Hello,
>
> This is a small idea I had recently: to update the rest operator to make
> it work not only to get the last elements.
>
> As an example, we already have:
>
> ```javascript
> const myArray = [1, 2, 3, 4, 5, ..., 99, 100];
> [first, second, ...rest] = myArray;
>
> // first = 1
> // second = 2
> // rest = [3, 4, 5, ..., 99, 100]
> ```
>
> It would be interesting to have:
>
> ```javascript
> [...rest, previous, last] = myArray;
>
> // rest = [1, 2, 3, ..., 97, 98]
> // previous = 99
> // last = 100
> ```
>
> And:
>
> ```javascript
> [first, ...rest, last] = myArray;
>
> // first = 1
> // rest = [2, 3, ..., 97, 98, 99]
> // last = 100
> ```
>
> Another use case: inside a variadic function to separate the callback
> (often the last argument) and the function parameters.
>
> I asked myself «why would I want the last elements of an array», and my
> answer was «for the same reason which motivates me to get the first
> ones».
>
> What do you think ?
>
> --
>   Siegfried Ehret
>   siegfried at ehret.me
>   +33 (0) 6 22 68 17 44
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170802/0fc3e231/attachment.html>


More information about the es-discuss mailing list