length property value for functions with parameter enhancements

Brendan Eich brendan at mozilla.com
Mon Aug 29 13:36:34 PDT 2011


On Aug 29, 2011, at 11:29 AM, Allen Wirfs-Brock wrote:

>> Hm, that doesn't sound like a very JavaScripty argument :). If you buy
>> into optional arguments at all, then I can certainly envision valid
>> use cases for combining them with rest arguments.
> 
> Which is the source of the potential confusion because all of the "optional" parameters get populated with values before the rest argument gets any values.  

There's no confusion, IMHO. The order is left to right -- this matters for parameter default values in and of themselves. The precedent in nearby languages is strong. I am pretty opposed to making this an error case. It cannot of course be a case where right-to-left evaluation happens in any form (rest parameter "eats" actuals, leaving none in the middle for default parameters).


>> I guess I don't see what is special about empty argument lists. Why
>> would you want to make a clearer distinction between the argument
>> lists () and (a=0), than between (x) and (x, a=0)? You seem to be
>> introducing a discontinuity.
> 
> Given, that I have yet to think of a reasonable use case for function length properties, all of these rationalizations a pretty conceptual.
> 
> However, () seems like a clear statement that no arguments are required or expected while (a=0) says that an argument does have some meaning.  This seems like a worthwhile distinction to make even though 1 may not be the "typical" number of arguments.

You can't use one integer-valued property to convey two meanings. F.length is either minimum non-default/rest parameters, or a count of non-rest parameters. I don't see a sane alternative. The count of non-rest parameters is not that interesting, since it is one fewer than the full count of all parameters (modulo destructuring, where it must count each actual position, not all the names of destructured-to formals). That leaves F.length counting only non-default/rest params.

/be


More information about the es-discuss mailing list