Rest parameter anywhere

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Apr 17 10:14:59 PDT 2014


wasn't that obvious to me ... anyway, the first, ...mess, last example
convinced me ^_^


On Wed, Apr 16, 2014 at 5:27 AM, Егор Николаев <termi1uc1 at gmail.com> wrote:

> ```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
>>
>
>
> _______________________________________________
> 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/20140417/b29e56aa/attachment.html>


More information about the es-discuss mailing list