"Exception: parameter(s) with default followed by parameter without default"

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Oct 10 09:09:24 PDT 2012


On Oct 10, 2012, at 6:19 AM, David Bruant wrote:

> Hi,
> 
> I've tried the following on Firefox:
> 
>   function f(a, b = 34, c){
>       console.log('b', b)
>   }
> 
>   f(1, undefined, 43)
> 
> and got "Exception: parameter(s) with default followed by parameter without default"
> It seems intentional, but I wonder why it's been decided this way.


That isn't a specified error and this function should be legal.  For example, see the note in the definition of ExpectedArgumentCount in section 13.1 of the 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 is allowed after the first parameter with an initializer but such parameters are considered to be optional with undefined as their default value.



Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121010/b39310ca/attachment.html>


More information about the es-discuss mailing list