Argument matching

Michael O'Brien mob at mbedthis.com
Fri May 9 11:48:50 PDT 2008


> Presumably what you're getting at is that if 'checker' is strict  
> then it
> must accept three arguments even if we only care about one.  This is  
> so.
> The easiest way to write down a function like that is to use the rest
> parameter without a parameter name:
>
>  function f(obj, ...) { /* code here */ }


Agree, but that may have a performance penalty as the extra args must  
be converted to an array. One case where strict mode may be faster  
than standard ;-)

So that I can write up a bug for the RI, my take on the rules is:

- In strict mode, the number and types of args must agree. If not, an  
error is generated.

- In standard mode, you can supply too many actual parameters, they  
will be ignored. If you supply too few, undefined will be  
automatically supplied for the missing args.

The RI exhibits strict behavior in this regard in standard mode.

Michael



On May 9, 2008, at 11:37 AM, Lars Hansen wrote:
>> -----Original Message-----
>> From: Michael O'Brien [mailto:mob at mbedthis.com]
>> Sent: 9. mai 2008 11:09
>> To: Lars Hansen
>> Cc: es4-discuss Discuss
>> Subject: Re: Argument matching
>>
>> Comments below:
>> On May 9, 2008, at 10:43 AM, Lars Hansen wrote:
>>> In strict code ("use strict") the number of passed arguments must
>>> match the number of expected arguments.  This has been agreed upon.
>>
>> I presume that is at execution time?
>
> It is.
>
>> So for Array.some in strict mode, the user must supply 3 typed
> arguments
>> for the callback.  But in standard mode, they can either do that, or
> supply
>> one untyped arg.
>
> static function some(object:!Object, checker:Callable,
> thisObj:Object=null): boolean {
>    for (let i=0, limit=object.length; i < limit ; i++)
>        if (i in object)
>            if (checker.call(thisObj, object[i], i, object))
>                return true;
>    return false;
> }
>
> The type of 'checker' used to be Checker:
>
>    type Checker = function (*, double, Object):boolean;
>
> but that is painful in practice.  The intrinsic instance method still
> requires a Checker, though.
>
> Presumably what you're getting at is that if 'checker' is strict  
> then it
> must accept three arguments even if we only care about one.  This is  
> so.
> The easiest way to write down a function like that is to use the rest
> parameter without a parameter name:
>
>  function f(obj, ...) { /* code here */ }
>
> --lars




More information about the Es4-discuss mailing list