In the scenario below, I have a boolean value. Depending on the result, I call the exact same function with the only difference being the number of parameters.
var myBoolean = ...
if (myBoolean) {
retrieveData(param1, function(err, result) {
if (err) throw err;
// process
});
}
else {
retrieveData(param1, param2, function(err, result) {
if (err) throw err;
// process
});
}
At the moment it feels like I’m repeating a lot of code unnecessarily. Is there a way to consolidate this so I’m not repeating the same thing?
If the situation is as simple as this, then just save the repeated function in a variable: