Appunni Appunni - 2 years ago 99
Javascript Question

How to find number of arguments that come into a constructor in node.js

I have a constructor in node.js as follows.

function Tree() {
//Redirect to other functions depends upon argument count.

And i created objects like

var theTree = new Tree('Redwood');
var theTree = new Tree('Redwood',5);
var theTree = new Tree('Redwood',10,"USA");

My requirement is that i want to redirect to different functions depending upon the number of arguments that came to constructor. How can I find the number of arguments ?

Answer Source

You simply use the arguments.length variable.

For more info you can read about the arguments object:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download