Trailing comma for function arguments and call parameters

Alex Kocharin alex at kocharin.ru
Sun Jul 6 01:07:09 PDT 2014


In fact, how about the same syntax for arrays and function calls? With trailing commas and elisions?

So foo(1,,3,,) would be an alias for foo(1,undefined,3,undefined) ?


06.07.2014, 11:57, "Alex Kocharin" <alex at kocharin.ru>:
> Unless you use leading comma style, trailing commas are very good to have for anything that has variable amount of items/keys/arguments.
>
> This is a classic example I use to show why JSON is a bad idea: https://github.com/npm/npm/commit/20439b21e103f6c1e8dcf2938ebaffce394bf23d#diff-6
>
> I believe the same thing applies for javascript functions. If it was a bug in javascript, I wish for more such bugs really...
>
> 04.07.2014, 20:33, "Oliver Hunt" <oliver at apple.com>:
>>  On Jul 3, 2014, at 3:52 PM, Dmitry Soshnikov <dmitry.soshnikov at gmail.com> wrote:
>>>   Hi,
>>>
>>>   Will it makes sense to standardize a trailing comma for function arguments, and call parameters?
>>>
>>>   We have it for Array and Object initialisers, and people like using them for long lists with prediction of new items adding in the future:
>>>
>>>   ```
>>>   var modes = [
>>>     read,
>>>     write,
>>>   ];
>>>
>>>   var platforms = {
>>>     web,
>>>     canvas,
>>>   };
>>>   ```
>>  I suspect, but brendan could tell us otherwise, that the allowance of trailing commas is a result of a bug in the _early_ _early_ days of JS, which then got matched by the wonders of bug for bug compat, and so became necessary for web compatibility.
>>
>>  Also, i’m not sure that your intended uses is sufficiently compelling to justify non-backwards compatible syntax (i’m not against adding new syntax, i just feel that it needs to have substantial benefits)
>>
>>  Hence, i don’t think this should be extended to other constructs.
>>
>>  —Oliver
>>  _______________________________________________
>>  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


More information about the es-discuss mailing list