On Wed, Sep 10, 2008 at 6:33 PM, David-Sarah Hopwood
<[EMAIL PROTECTED]> wrote:
> Garrett Smith wrote:
>> On Wed, Sep 10, 2008 at 3:41 PM, David-Sarah Hopwood
>> <[EMAIL PROTECTED]> wrote:
>>> Mark S. Miller wrote:
>>>> On Tue, Sep 9, 2008 at 9:51 PM, Brendan Eich <[EMAIL PROTECTED]> wrote:
>> Why would "Function.apply3" need three arguments?
>
> Because Function.prototype.apply takes two arguments, and apply3
> (or staticApply, or whatever it is called) makes the 'this' argument
> explicit.
>
>> Function.prototype.apply doesn't actually need any arguments.
>
> No, it always takes two arguments, which may be undefined. But since
> an undefined argument can't be distinguished from a missing one, that
> does mean it's not possible to condition on whether there are two or
> three arguments. (Besides, I withdrew the suggested name 'apply3'.)
>
No, it doesn't always take two arguments. It takes whatever arguments
I pass it. I just called it with 0 arguments and it took that.
A missing argument could absolutely be distinguished from an argument.
function countArgs(a, b) {
if(a === undefined && b === undefined) {
alert(arguments.length);
}
}
When a countArgs is enterered, the Variable object gets the properties
|a| and |b|. If the caller supplied fewer arguments than the number or
formal parameters, the extra formal parameters have value |undefined|
The |arguments| object is initialized with a |length| property that
holds the number of actual parameter values supplied by the caller.
Thus:
countArgs(undefined, undefined);
elerts "2"
>> See for yourself:-
>>
Garrett
> --
> David-Sarah Hopwood
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss