1

It is possible to check if function expect/need any data?

function one(){

}
function two(ineedvar){

}

So i have to functions and I would like to check which of them need var between ().

Piotrek
  • 10,919
  • 18
  • 73
  • 136

2 Answers2

6

You can use .length property of the function to see if it takes any argument.

i.e two.length

Fiddle

Reference

But note that function can also take arguments without having it define it in the function declaration, so can't rely on that always.

PSL
  • 123,204
  • 21
  • 253
  • 243
2

Use length property of the Function object:

one.length /* 0 */
two.length /* 1 */
Denys Popov
  • 1,040
  • 12
  • 14