Wexoni Wexoni - 1 year ago 81
Node.js Question

Function - Passing the arguments.

I have a large code base, and I am tasked to implement additional functionality. Code is Node.js - Javascript.

There is one function, and it goes like this:

function checkPeople(first, second) {
if(second) {
//do some things...

That same function is called several times, but generally it is called like:



checkPeople(first, second);

It depends what is being used for. the parameter "first" is always send regardless.

Now I have to add extra functionality to the same function but with the third parameter:

function checkPeople(first, second, third) {
if(second) {
//do some things...
if(third) {
//do some things

I was thinking to add third parameter to the function, wherever the function is being called (around 2 times), and check for the existance of the parameter inside the function. Which it is already done for the the parameter "second".

Is this approach valid?

Thank you

Answer Source

If you pass in the argument like this when you call the function, using null as the second argument, it will not call the second. Assuming that is what you are trying to do. checkPeople(first, null, third)

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