- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Tue, 18 Jun 2013 11:18:21 -0400
- To: Allen Wirfs-Brock <allen@wirfs-brock.com>
- CC: Cameron McCormack <cam@mcc.id.au>, Brendan Eich <brendan@mozilla.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
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. http://wiki.ecmascript.org/doku.php?id=harmony:parameter_default_values says: Added restriction not expressed by this grammar: only trailing formal parameters may have default values specified by = AssignmentExpression 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 http://people.mozilla.org/~jorendorff/es6-draft.html has quite different language which matches what you're quoting. Has the spec just changed recently? 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 all. -Boris
Received on Tuesday, 18 June 2013 15:18:57 UTC