Function.length and Default Parameters

Norbert Lindenberg ecmascript at norbertlindenberg.com
Fri Oct 12 09:19:13 PDT 2012


There was additional discussion of length in the context of the internationalization API, and a decision at the July TC 39 meeting to "Apply ES6 rules to all functions in Internationalization API." [1]

By ES6 rules we meant what Allen had proposed [2] and what's in section 13.1 of the ES6 draft:

"NOTE	The ExpectedArgumentCount of a FormalParameterList is the number of FormalParameters to the left of either the rest parameter or the first FormalParameter with an Initialiser. A FormalParameter without an initializer are allowed after the first parameter with an initializer but such parameters are considered to be optional with undefined as their default value."

This means, optional arguments don't count.

[1] https://mail.mozilla.org/pipermail/es-discuss/2012-July/024207.html
[2] https://mail.mozilla.org/pipermail/es-discuss/2011-August/016361.html

Norbert


On Oct 12, 2012, at 8:53 , Allen Wirfs-Brock wrote:

> 
> On Oct 11, 2012, at 8:11 PM, Rick Waldron wrote:
> 
>> 
>> On Thursday, October 11, 2012 at 7:36 PM, Kevin Smith wrote:
>> 
>>> 
>>> express for node already does this, for error handlers:
>>> 
>>>     http://expressjs.com/guide.html#error-handling
>>> 
>>> express is very popular; #4 on Most Depended Upon packages; #1 on Most Starred at npm: 
>>> 
>>>  
>>> This is helpful.  So, judgement aside, we can say there is a certain level of usage of Function.length out there for overloading based on a function's "signature".  It seems to me that reporting Function.length as the number of formal parameters, minus rest, will be more appropriate for this use case.
>> 
>> Having trouble finding the resolution, but I'm fairly certain this was discussed and your suggestion here matches consensus 
> 
> Previous threads where this topic was discussed:
> 
> https://mail.mozilla.org/pipermail/es-discuss/2012-June/023277.html 
> 
> https://mail.mozilla.org/pipermail/es-discuss/2011-August/016361.html 
>    https://mail.mozilla.org/pipermail/es-discuss/2011-September/016417.html 
> 
> There was no consensus to change the current ES6 draft specification for function length.
> 
> Allen
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list