Ignoring arguments

Cyril Auburtin cyril.auburtin at gmail.com
Sun May 29 20:56:18 UTC 2016


Since functions arguments is an array under the hood, they could 'more
behave the same'

Both function arguments and arrays accept spreading: *[1, 2, ...args]
* and *fn(1,
2, ...args)*

a function definition like *(,i) => {}*, would be the equivalent of *var
[,i] = arguments*

an invocation *fn(,,i)* would be the equivalent of *[,,i]*

It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but
slightly less simply

Are there possible issues with that 'extension' of function syntax?


2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>:

> You could stop with "rare"; having to make up unused names is an obvious
> smell in comparison.
>
> ```js
> foo(UNUSED1, UNUSED2, x)
>
> foo(_, __, x)
>
> foo(,, x)
>
> foo(...[,, x])
> ```
>
> The latter is shorter and more explicit and would not be any more
> confusing if it became common.
>
>
> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote:
>
>> Eliding array elements is not "similar" to eliding function formal
>> parameters. The latter is extremely rare, hardly readable, confusing,
>> bug-prone, and unnecessary because there is already a "standard way" which
>> is to use any old parameter name you want:
>>
>> ```js
>> function foo(UNUSED1, UNUSED2, x)
>> ````
>>
>> Most linters will not complain, or there are ways to shut them up if they
>> do.
>>
>> If you want to throw away an argument, just throw it away.
>>
>> ```js
>> function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); }
>>
>> `[1,2,3,4].map(skipFirstParam(i => i));
>>
>> ```
>>
>> Or use Renki's solution.
>>
>> Bob
>>
>>
>> On Sun, May 29, 2016 at 9:23 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
>>>
>>>
>>
>> _______________________________________________
>> 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/488ffa04/attachment.html>


More information about the es-discuss mailing list