Piotrek
Piotrek

Reputation: 11221

Check if function expect any data

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 ().

Upvotes: 1

Views: 64

Answers (2)

PSL
PSL

Reputation: 123739

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.

Upvotes: 6

Dennis Gawrisch
Dennis Gawrisch

Reputation: 1060

Use length property of the Function object:

one.length /* 0 */
two.length /* 1 */

Upvotes: 2

Related Questions