bypassing function argument without changing default value
Hi there
I’m having some problems understanding how I can bypass function arguments without changing its default value. Here are some examples:
function myFunction ( arg1:Boolean, arg2:String="default string", arg3:Number=3 ):Array
{
return new Array (arg1, arg2, arg3);
}trace(myFunction(true, "new string", 5));
// true,new string,5trace(myFunction(true, undefined, 5));
// true,,5trace(myFunction(true, null, 5));
// true,,5trace(myFunction(true));
// true,default string,3trace(myFunction(true, null));
// true,,3
My question is: Shouldn't I be able to call a function bypass the second argument (that has a default value), change third argument and on result second argument maintains its default value?
Example:
trace(myFunction(true, null, 5));
// not desired: true,,5
// desired: true,default string,5
I know that applying a defult value to the argument allows one to bypass it. But it will always be redefined or to null or to undefined. At the moment I only see one solution.
function myFunction ( arg1:Boolean, arg2:String="default string", arg3:Number=3 ):Array
{
if (!arg2)arg2 = "deafult string";
return new Array (arg1, arg2, arg3);
}
It just seems like too much code repeated
Regards