Re: Reconciling handling of optional arguments and handling of default values across ES and webidl

On 6/18/13 11:00 AM, Allen Wirfs-Brock wrote:
> Cameron, Either I'm misinterpreting what you are trying to say or you misunderstand what Boris said.  ES6 does allow a parameter with an explicit default value to be followed by one without an explicit default value.

I think part of the issue here is that the state of "ES6" is unclear to 
at least me. 

     Added restriction not expressed by this grammar: only trailing
     formal parameters may have default values specified by =

and that matches what SpiderMonkey, at least, implements:

   js> function f(a = 5, b) {}
   typein:1:18 SyntaxError: parameter(s) with default followed by
   parameter without default:
   typein:1:18 function f(a = 5, b) {}
   typein:1:18 ..................^

and what SpiderMonkey developers I asked about the behavior told me the 
spec says.  On the other hand has quite different 
language which matches what you're quoting.  Has the spec just changed 

It's not clear to me whether the current spec allows this:

   function f(a, b = 5, c, d = 7, e) { }

If it does, great; that basically matches what I'm proposing WebIDL 
should do, which is allow putting default values on the optional 
arguments where they make sense no matter what the argument order is.

> This is all about determining the "length" value of a function.  Length is the number of required arguments which is defined to be the number of formal parameters to the left of  the first parameter with a default value initializer (or the rest parameter).

The "length" of a function is an orthogonal (and somewhat simpler, in 
that it really doesn't matter all that much in practice, imo) issue. 
Right now we're just talking about what sort of functions are allowed at 


Received on Tuesday, 18 June 2013 15:18:57 UTC