Yes, there is: use the Function.length property. I just checked the docs : it doesn't seem to be mentioned there.
trace(foo.length); //0 trace(bar.length); //2 trace(jad.length); //2
Note that there are no curly braces () after the function name. You need a reference to the Function object; adding curly braces will execute the function.
I do not know how to find out that one of the arguments is optional.
EDIT
How about ... relaxation options ?
function foo(...rest) {} function bar(parameter0, parameter1, ...rest) {} trace(foo.length);
This makes sense as there is no way to know how many arguments will be passed. Please note: inside the function body, you can know exactly how many arguments were passed, for example:
function foo(...rest) { trace(rest.length); }
Thanks to @felipemaia for pointing this out.
source share