One more similarity is that both function parameters and destructuring allow default values: (foo = 1) vs [foo = 1].
On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin <[email protected]> wrote: > 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 <[email protected]>: > >> 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 <[email protected]> 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 < >>> [email protected]> 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 >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

