Function length
Mariusz Nowak
medikoo+mozilla.org at medikoo.com
Mon Jun 11 12:11:37 PDT 2012
I find Function 'length' as very useful property (I use it in some low-level
functional stuff). I also think that defining functions so it reflects only
required arguments is very sane decision. In that light I would also expect
...rest to not be counted in Function length.
+1 for keeping it, the way it is.
Brendan Eich-2 wrote:
>
> 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 <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
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-----
Mariusz Nowak
https://github.com/medikoo
--
View this message in context: http://old.nabble.com/Function-length-tp33987815p33995683.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.
More information about the es-discuss
mailing list