Get a function’s arity

> zero.length
0
> one.length
1
> two.length
2

Source

A function can determine its own arity (length) like this:

// For IE, and ES5 strict mode (named function)
function foo(x, y, z) {
    return foo.length; // Will return 3
}

// Otherwise
function bar(x, y) {
    return arguments.callee.length; // Will return 2
}

Leave a Comment