Function.length and Default Parameters

Kevin Smith khs4473 at
Fri Oct 12 09:30:40 PDT 2012

> 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.

Sure, it's not breaking, but that doesn't mean that it makes sense for the
use case we're talking about.


    function f(a = 1, b, c) {}
    f.length === 0; // Huh?

On what basis does reporting 0 make sense?  How does that communicate
anything at all about the function?

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

More information about the es-discuss mailing list