Argument matching

Michael O'Brien mob at mbedthis.com
Fri May 9 10:29:32 PDT 2008


What should ES4 do when there are too many or too few arguments?

Seems that the RI will apply different behavior depending on whether  
the function arguments are typed or not. This is not necessarily  
unexpected. I just want to nail down the rules as the RI and AS3  
behave differently in this regard.

Consider:

function fun(a, b) {
	print(a);
	print(b);
}

Calling this with:

fun(1)			prints
	1
	undefined

fun(1,2,3,4)		prints
	1
	2

fun(1,undefined)
	1
	0	

both work without error.

But if either arg is typed:

function fun(a: int, b) {
	print(a);
	print(b);
}

In this case, the following all get TypeErrors

fun(1)
fun(1, undefined)
fun(1,2,3,4)

Interestingly, ASC will coerce "undefined" to 0 if supplied with the  
correct number of arguments and they are typed as ints.

What are the rules for ES4?

- If you type formal arguments, it seems the caller must supply the  
correct number and type of actual parameters
- If you don't type the formal arguments, you can supply too few or  
too many arguments
- Should undefined be coerced to 0 if the type is an integer?

Michael



More information about the Es4-discuss mailing list