Dave Merrill
01/26/2023, 2:37 PMwebsolete
01/26/2023, 2:59 PMwebsolete
01/26/2023, 3:03 PMThe Arguments scope is special, as it is BOTHa struct AND an array
When you dump the arguments scope, it always appears as a struct
However, you can also treat it like an array in order to find out which arguments are actually being passed in
For example, if you do arraylen(arguments) you will get how many arguments were passed in during the method call (vs how many may be defined as arguments, which may or may not have default values)
Additionally, you could do something like this to actually see which arguments were passed in:
for(var i = 1; i <= arraylen(arguments); i++) {
writeoutput("argument #i#: " & arguments[i] & "<br>");
}
IsArray(arguments) will always return false, howeverAdam Cameron
websolete
01/26/2023, 3:03 PMwebsolete
01/26/2023, 3:04 PMwebsolete
01/26/2023, 3:05 PMwebsolete
01/26/2023, 3:07 PMwebsolete
01/26/2023, 3:16 PMpublic any function doWhatever(
required string username,
numeric age = 0,
string location
) {
var args = {
"username" : "",
"age" : 0,
"location" : "Earth"
};
for( var a in args ) {
if( arguments.keyExists(a) ) {
args[a] = arguments[a];
}
}
// now only those args that you care about are available in the args struct with any values that may have been passed in
}websolete
01/26/2023, 3:18 PMAdam Cameron