Argument matching
Lars Hansen
lhansen at adobe.com
Fri May 9 11:37:01 PDT 2008
> -----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