Function length
Irakli Gozalishvili
rfobic at gmail.com
Mon Jun 11 10:56:45 PDT 2012
> I don't think any library should ever rely on f.length.
>
>
That's a wrong attitude, there always will be legitimate uses of any feature, otherwise such features are just harmful & IMO should be deprecated / removed.
> It is not a
> reliable source of information (f might use 'arguments' even when the
> length is officially 0), and I don't honestly see it being useful for
> anything but tertiary debugging purposes.
>
>
In some cases weather function captures `rest` arguments via `arguments` is irrelevant. Like in a case I've pointed out earlier. Library provides arity based dispatch based on f.length, so if you pass `function() { arguments…. }` it will never be called with more than 0 arguments.
Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/
On Monday, 2012-06-11 at 05:33 , Andreas Rossberg wrote:
> On 10 June 2012 03:52, Irakli Gozalishvili <rfobic at gmail.com (mailto:rfobic at gmail.com)> wrote:
> > I just noticed strange behavior in spider monkey implementation of rest
> > arguments:
> >
> > (function(a, b, ...rest) {}).length // => 2
> >
> > I think ignoring `rest` in length is pretty counter intuitive. For example I
> > have small utility function that
> > I use to dispatch depending on argument length.
> >
> > var sum = dispatcher([
> > function() { return 0 },
> > function(x) { return x },
> > function(x, y) { return x + y },
> > function(x, y, z) { return Array.prototype.slice.call(arguments,
> > 1).reduce(sum, x) }
> > ])
> >
>
>
> I don't think any library should ever rely on f.length. It is not a
> reliable source of information (f might use 'arguments' even when the
> length is officially 0), and I don't honestly see it being useful for
> anything but tertiary debugging purposes.
>
> /Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120611/7ec714a9/attachment-0001.html>
More information about the es-discuss
mailing list