I have an array of functions, as in:
funcArray = [func1, func2, func3];
When in a given function, I want to execute the next function in the array. How do I do this? Here is my basic skeleton:
function func1() {
// I get current function caller
var currentFunc = func1.caller;
// I want to execute the next function. Happens to be func2 in the example.
}
I cannot use indexOf function, as one would for an array of strings or numbers.
NOTE: This question appears to be similar to this and the one it refers to. However, it is a different question.
I want to alter the sequence of processing by merely modifying the array. That's the goal. A possibly more efficient approach would be appreciated.
Clarification: Based upon some of the comments: funcArray is global.
The goal is to implement middleware for a Node.js HTTP module in as simple and efficient a manner as possible without using any third-party modules.
func1knows nothing aboutfuncArrayafter you call it. Function is just a reference and it may be stored in an array, in object or wherever else. Caller function should worry about the order of execution in this case.funcArray.indexOf(func1)? It works with strings, numbers or objects like functions.func1need to know aboutfunc2at all? Shouldn't they be executed separately, by the caller? Do you just want to try calling the array functions in a loop until the first returns true or something?