Let's say I have this code:
function QueCalculamos(valor) {
function CalculaADeB() {
console.log( "Calculando A de B");
}
function CalculaBDeA() {
console.log( "Calculando B de A");
}
if (valor =="A") { return CalculaADeB; }
else if (valor == "B") { return CalculaBDeA; }
}
let bvla="B";
var exe = QueCalculamos(bvla);
exe();
Depending on the value I pass to "QueCalculamos", it will execute one function or the other.
But let's suppose that I don't have to choose between two functions, but among many, and that they are a bit large. For code readability purposes, I would like to define "CalculaADeB" and "CalculaBDeA" separately, outside "QueCalculamos".
How would I return a reference to those functions in that case? And if it's not possible, how would you organize the code to make it more readable then? (Maybe I don't have enough experience with modern Javascript, but this whole "define a function inside a function" thing always looks messy to me).