Function length

Allen Wirfs-Brock allen at
Sat Jun 9 23:54:04 PDT 2012

On Jun 9, 2012, at 6:52 PM, Irakli Gozalishvili wrote:

> I just noticed strange behavior in spider monkey implementation of rest arguments:
> (function(a, b, {}).length // => 2

That answer is consistent with what is specified in the ES6 draft spec.  The actual value is specified algorithmically  and is summarized by this note:

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.

See section 13.1.

The draft is based upon the conclusions that were reached when this was last discussed.  See the thread starting 

There is no obviously "right" answer to what should be reported as the length (and it isn't clear whether this property really has any utility).  The closest thing we have to legacy precedent are these statement from previous versions of the spec:

15 Every built-in Function object described in this clause—whether as a constructor, an ordinary function, or both—has a length property whose value is an integer. Unless otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the function description, including optional parameters. The value of the length property is an integer that indicates the “typical” number of arguments expected by the function.

Note that that the the legacy description is not particularly self consistent and that where a length value is "other specified" for various built-in functions it tends to follow the rule.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list