length property value for functions with parameter enhancements

Brendan Eich brendan at mozilla.com
Mon Aug 29 17:13:38 PDT 2011


On Aug 29, 2011, at 4:38 PM, Allen Wirfs-Brock wrote:

> 2) the number of parameter positions (including the rest parameter if specified) that precede the first default-value parameter (or the end of the list if there are no default-value parameters):
>  function (a,b,c) {}  //length==3
>  function (a,b,...c) {}  //length==3  
>  function (...c) {} // length=1
>  function (a=1,b=2) {}  //length==0
> function (a,b=1) {}  //length==1
> function (a,b=1,...c) {}  //length==1
> ...
> 2) Treats rest as meaning "usually at least one" (unless following a default-value parameter) which seems to be the way open-ended parameter lists were interpreted in assigning length to most such Chapter 15 functions.  I think that this rule would yield the most matches  with the specified lengths of chapter 15 functions when their signatures are rewritten using default-value and rest parameter notation.

I like this best, thanks for writing it out. The function(a,b=1,...){}.length === 1 condition in particular.

Ok, here are some results from a very brief browsing session with logging of F.length turned on for any function F:

http://images.nationalgeographic.com/wpf/sites/common/j/jquery/jquery_1.4.2.min-cb1282247955.js:91 4
http://images.nationalgeographic.com/wpf/sites/common/j/jquery/jquery_1.4.2.min-cb1282247955.js:91 0
http://pluck.nationalgeographic.com/ver1.0/Content/ua/scripts/pluckApps.js:266 4
http://test262.ecmascript.org/resources/scripts/global/jquery-1.4.2.min.js:91 4
http://test262.ecmascript.org/resources/scripts/global/jquery-1.4.2.min.js:91 0
http://static.ak.fbcdn.net/rsrc.php/v1/y1/r/RS_vQKTP5Zl.js:7 0
http://static.ak.fbcdn.net/rsrc.php/v1/y1/r/RS_vQKTP5Zl.js:7 0

The format is file:line length.

I need to fix SpiderMonkey to give column-based blame for those minimized jquery-1.4.2.min.js lines to be useful.

Anyway, plenty of evidence that F.length is used.

/be





More information about the es-discuss mailing list