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
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