Function.length and Default Parameters

Allen Wirfs-Brock allen at
Fri Oct 12 09:13:41 PDT 2012

On Oct 11, 2012, at 4:36 PM, Kevin Smith wrote:

> express for node already does this, for error handlers:
> express is very popular; #4 on Most Depended Upon packages; #1 on Most Starred at npm: 
> This is helpful.  So, judgement aside, we can say there is a certain level of usage of Function.length out there for overloading based on a function's "signature".  It seems to me that reporting Function.length as the number of formal parameters, minus rest, will be more appropriate for this use case.

Have you found the actual usage of length in node libraries to enforce this sort of signature testing?  I was poking around and haven't found it.  Note that the only says "must be defined with an arity of 4, that is the signature (err, req, res, next)".  It doesn't say that length is use to enforce this.  It might be doing a toString on the function or something else.

Regardless,  the specification function length in the current ES6 draft would not break such length-based detection.  If you write function (err, req,res,next){}.length you will get 4, just like with ES5.1  So this isn't a breaking change.  Any new use of new parameter forms would be a violation of the "must" in the above quote from the express documentation.

So, so far, I have really seen anything new in this recent thread that would cause us to change the decision that has already been made.


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

More information about the es-discuss mailing list