length property value for functions with parameter enhancements
allen at wirfs-brock.com
Thu Sep 1 10:38:53 PDT 2011
On Sep 1, 2011, at 8:55 AM, Dean Landolt wrote:
> On Thu, Sep 1, 2011 at 11:38 AM, Rick Waldron <waldron.rick at gmail.com> wrote:
> Just want to clarify that neither jQuery nor its selector engine Sizzle have any occurrences of function arity checking via the function length property. Both codebases have occurrences of arguments.length checking
> FTR this kind of arity checking is pretty common in the node.js world: https://github.com/kriszyp/promised-io/blob/master/promise.js#L619
To clarify, it is indeed function arity checking that node.js is performing. In this case, it is assuming (maybe "requiring" is closer to fact) that all "async functions" take a callback as their last argument. and using that fact to generate wrapper functions that replace the callback function.
This pattern would break under the proposal we are discussing if somebody tried to define an "async function" with default value or rest parameters. However, it would also break today if somebody tried to define an "async function" that solely used its arguments object to access arguments and neglected to declare any formal parameters. Presumably in either case node.js should tell its users not to use such parameter patterns in defining "async functions".
Regardless of whether or not we counted optional value parameters in determining the value of a function's length property this node.js pattern would be problematic if callers actually made use of the ability to optionally include/exclude default value arguments. So, it's not clear that this use case helps us much in design our length value algorithm.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss