Possible Duplicate:
Get a function's arity
Say I have:
function a(x) {};
function b(x,y) {};
I want to write a function called numberOfParameters that returns the number of parameters that a function normally accepts. So...
numberOfParameters(a) // returns 1
numberOfParameters(b) // returns 2
function f(x) { }
function g(x, y) { }
function param(f) { return f.length; }
param(f); // 1
param(g); // 2
Disclaimer: This should only be used for debugging and auto documentation. Relying on the number of parameters that a function has in it's definition in actual code is a smell.
.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