Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get function arguments count from external scope

Tags:

javascript

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?
like image 409
Peter Avatar asked Oct 21 '25 04:10

Peter


2 Answers

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.

like image 178
Andy Avatar answered Oct 23 '25 16:10

Andy


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

like image 34
Mritunjay Avatar answered Oct 23 '25 16:10

Mritunjay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!