Trailing comma for function arguments and call parameters

Brendan Eich brendan at mozilla.org
Sun Jul 6 21:06:52 PDT 2014


Oliver Hunt wrote:
> 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.

No, trailing commas in array and object literals were intentional, to 
ease maintenance (counterexample: ANSI and ISO C enum).

The requirement for two adjacent commas to make a hole in an array, 
unless the hole is at index 0 (in which case one comma obviously is the 
right number), follows. IE JScript had a notorious bug where one 
trailing comma in an array literal made a hole, but that's long fixed.

/be


More information about the es-discuss mailing list