Possible Duplicate:
Get a function’s arity
How can I declare a function expression, pass it into a defined function, and have the defined function determine how many arguments the function expression has?
See this code snippet for reference:
function getArgumentCount(fexp)
{
return ...;
}
var fexp1 = function(a) { };
var fexp2 = function(a, b) { };
console.log(getArgumentCount(fexp1)); // Should output 1
console.log(getArgumentCount(fexp2)); // Should output 2
length property contains the number of arguments passed to the function.
We will use len() function or method in *args in order to count the number of arguments of the function in python.
Arbitrary Arguments, *args If you do not know how many arguments that will be passed into your function, add a * before the parameter name in the function definition.
To call a function with a variable number of arguments, simply specify any number of arguments in the function call. An example is the printf function from the C run-time library. The function call must include one argument for each type name declared in the parameter list or the list of argument types.
javascript functions have a .length property
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/length
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With