I would not mind removing Function 'length' but on the web you cannot deprecate and any browser daring to remove will appear broken to users not involved in the content or the engine, and users switch browsers.

Anyway, back to reality: foo.length is in ECMA-262 and we need to spec how it works in the presence of a trailing rest parameter. Allen has drafted something based on discussion here. It's a plausible design and hard to criticize without both your use-case (in detail) and a better alternative.

/be

Irakli Gozalishvili wrote:
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 <rfo...@gmail.com <mailto:rfo...@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

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to