Hacker News new | ask | show | jobs
by koolba 3300 days ago
Curious why?

I get the usefulness for arrays and object declarations. Particular to have cleaner diffs. But why for function calls?

4 comments

Prettifying long function signatures and calls. You can spread them across multiple lines with the same trailing comma syntax you might use with a multiline array or object literal.
> Particular to have cleaner diffs. But why for function calls?

Exactly the same reason :)

I suppose but that's usually an indication that an object would be more apt. If you have enough parameters that it needs to be wrapped, they're probably hard to track too.
Well no, since you can use object destructuring.

const fn = ( { arg1 = '', arg2 = [], arg3 = true } = {} ) => { }

But isn't this already valid with trailing commas?
One small benefit is that it's now easier to generate code.
I like it for `compose()` function calls. Changing the parameters and order is fairly common, so the trailing comma becomes convenient for moving and adding parameters.