Ignoring arguments

Logan Smyth loganfsmyth at gmail.com
Sun May 29 17:55:58 UTC 2016


```
function fn(...[a, b, c, ...rest]){}
```
is mostly no different than
```
function fn(...args){
    let [a, b, c, ...rest] = args;
}
```

This wasn't officially allowed in ES2015, where only an Identifier was
allowed as a rest param target in arguments, but the behavior has since
been expanded to cover this case in ES2016:
https://github.com/tc39/ecma262/commit/d322357e6be95bc4bd3e03f5944a736aac55fa50

Not that I think this example is particularly readable :)

On Sun, May 29, 2016 at 10:36 AM, Renki Ivanko <fatalis.erratum at gmail.com>
wrote:

> It works in V8 at least, so I assumed it's correct.
>
> On Sun, May 29, 2016 at 8:29 PM, Bob Myers <rtm at gol.com> wrote:
>
>> I'm quite sure this syntax is invalid.
>>
>>
>> On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com>
>> wrote:
>>
>>> You can already do it like this:
>>>
>>> ```js
>>> ((...[,,foo]) => foo)(1, 2, 3) // -> 3
>>> ```
>>>
>>>
>>> R. <http://untu.ms/>
>>>
>>> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <
>>> cyril.auburtin at gmail.com> wrote:
>>>
>>>> Similarly to:
>>>>
>>>> `var [,x,,y] = [1,2,3,4,5,6];`
>>>>
>>>> I think it could be interesting to let a field empty in function
>>>> arguments
>>>>
>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )`
>>>>
>>>> `function test(a,,b) { }`
>>>>
>>>> (but that would alter the current parsing, that doesn't allow it)
>>>>
>>>> Currently I often use `_` as a way to mark ignored fields, but when
>>>> there are more than 1 you need another identifier. A standard way would be
>>>> interesting rather
>>>>
>>>
>>
>
> _______________________________________________
> 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/20160529/2af85ec9/attachment-0001.html>


More information about the es-discuss mailing list