On Fri, Jan 11, 2019 at 6:42 AM Sultan <thysul...@gmail.com> wrote:
> >empty space with a comma?
>
> I think that only works with trailing params. For example this is not 
> possible:
>
> const foo = (a,  , c) => {}

It doesn't even "work" with trailing params. Function arglists can
*contain* a trailing comma, it's just ignored and does nothing. `const
foo = (a, b, )=>a+b` still has a .length == 2, and `(a, b, ,)=>a+b` is
just invalid syntax. The trailing comma is just allowed so you can
format a long arglist onto separate lines, and don't have to remember
that the last argument doesn't have a comma.

> >Today, you can write: const foo = (a, b, _) => {}
>
> However that does throw with:
>
> const foo = (a, _, _) => {}

Yup, I've run into that problem before, and had to hack around by
using `_1` for the second ignored arg. It's rare/niche enough that I'm
not sure it's worth solving, but I do acknowledge it as an annoyance.

> >You can already write: const [ , setState] = useState(0)
>
> Thanks i forgot about that.

Yeah, using holes *works*, but it's definitely harder to read than using _.

And the fact that the last trailing , does *not* create a hole isn't
relevant for destructuring, but it would be relevant and confusing for
function-arity if we allowed holes in arglists. That is,
`[1,2,].length` returns 2 list, while `[1,2,,].length` returns 3. If
we get pattern-matching and array literals can do strict length
checking, it would also become relevant and confusing. (But that's
several stacked "if"s!)

~TJ
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to