Ignoring arguments

Renki Ivanko fatalis.erratum at gmail.com
Sun May 29 19:32:44 UTC 2016


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/9c32f1d1/attachment.html>


More information about the es-discuss mailing list