What are the pros and cons of each option, considering long-term implications (increasing the number of functions / parameters, other developers taking over, etc.)?
Option 1: removes the need to pass foo
and bar
to each method, but will create nested functions that are hard to follow.
const myFunction = ({foo, bar}) => {
const results = []
const function1 = () => {
return foo + bar;
}
const function2 = () => {
return foo * bar;
}
const res1 = function1();
const res2 = function2();
results.push(res1, res2);
return results;
}
Option 2: you pass the parameters to each function, but remove the nesting, which in my opinion makes it more readable.
const function1 = ({foo, bar}) => {
return foo + bar;
}
const function2 = ({foo, bar}) => {
return foo * bar;
}
const myFunction = ({foo, bar}) => {
const results = []
const res1 = function1({foo, bar});
const res2 = function2({foo, bar});
results.push(res1, res2);
return results;
}
I would prefer to know how to improve my functional approaches here. Thank you!