I want a function to be able to take in various types. AS3 doesn't support overloading directly... so I can't do the following:
//THIS ISN'T SUPPORTED BY AS3
function someFunction(xx:int, yy:int, someBoolean:Boolean = true){
//blah blah blah
}
function someFunction(arr:Array, someBoolean:Boolean = true){
someFunction(arr[0], arr[1], someBoolean);
}
How can I work around it and still have a function that is able to take arguments of various types?
If you just want to be able to accept any type, you can use
*
to allow any type:If you have a large number of various parameters where order is unimportant, use an options object:
If you have a variable number of parameters, you can use the
...
(rest) parameter:For cases where you need to call a common function to a number of classes, you should specify the interface common to each class:
Could just have:
This way you can easily loop through your arguments and such too (and even check the argument type):