4

Is it possible to get function arguments count from external scope?

var foo = function(a,b,c) {
}

alert(foo.arguments.length); // how to do it? possible?
1
  • You want the number of expected parameters? Jul 15, 2014 at 10:04

3 Answers 3

4

You want Function.length:

function test(a, b, c) {
  // code
}

console.log(test.length); // 3

BTW, the number of expected arguments of a function is called the arity. There used to be a method called Function.arity but was deprecated in favour of Function.length.

3

try foo.length. It gives no of parameters defined in function definition.

3

Remove arguments in foo.arguments.length

foo.length
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.