Rest parameter anywhere

Егор Николаев termi1uc1 at gmail.com
Wed Apr 16 05:27:05 PDT 2014


```javascript
let [a = 1, b = 2, ...rest, c = 4, d = 5] = [9, 8, 7];
```
a == 9, b == 8, rest == [], c == 7, d == 5
obviously. As in coffeescript


On Fri, Apr 11, 2014 at 9:53 PM, Tab Atkins Jr. <jackalmage at gmail.com>wrote:

> On Fri, Apr 11, 2014 at 5:39 AM, Егор Николаев <termi1uc1 at gmail.com>
> wrote:
> > Long story short:
> > ```javascript
> > function test( a = 1, b = 2, ...rest, c = 4, d = 5) { console.log(a, b,
> > rest, c, d) }
> >
> > test();                // 1, 2, [], 4, 5
> > test(9, 8);            // 9, 8, [], 4, 5
> > test(9, 8, 7, 6);      // 9, 8, [], 7, 6
> > test(9, 8, 7, 6, 5, 4);// 9, 8, [7, 6], 5, 4
> >
> > let [a = 1, b = 2, ...rest, c = 4, d = 5] = [];                // a ==
> 1, b
> > == 2, rest == [], c == 4, d == 5
> > let [a = 1, b = 2, ...rest, c = 4, d = 5] = [9, 8];            // a ==
> 9, b
> > == 8, rest == [], c == 4, d == 5
> > let [a = 1, b = 2, ...rest, c = 4, d = 5] = [9, 8, 7, 6];      // a ==
> 9, b
> > == 8, rest == [], c == 7, d == 6
> > let [a = 1, b = 2, ...rest, c = 4, d = 5] = [9, 8, 7, 6, 5, 4];// a ==
> 9, b
> > == 8, rest == [7, 6], c == 5, d == 4
> > ```
>
> You skipped the most interesting case - what to do when the list is
> *almost* long enough to accommodate all of the non-rest params.
>
> `let [a = 1, b = 2, ...rest, c = 4, d = 5] = [9, 8, 7];`
>
> It seems, from your second test case, that a=9 and b=8, but which
> variables gets a value of 7 - c or d?
>
> ~TJ
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140416/b2b8ed80/attachment-0001.html>


More information about the es-discuss mailing list