I would like to achieve the following: I have a class generating an object with a series of methods. Each of these is likely to be a promise.
From the outside of it should be possible to pick these methods and compose them into an array and ask the same object to execute them in series.
The code should be something like this (of course this does not work, this is why I'm asking):
class Car{
constructor(){}
fuctionA(input){
// do stuffs
}
fuctionB(input){
// do stuffs
}
fuctionC(input){
// do stuffs
}
fuctionD(input){
// do stuffs
}
executeArrayOfFuctions(array){
// execute each function in the array when the previous is resolved
}
}
const car1 = new Car();
const car2 = new Car();
const arrayOfFunctions = [functionA(input), functionC(input), functionA(input)];
car1.executeArrayOfFuctions(arrayOfFunctions);
car2.executeArrayOfFuctions(arrayOfFunctions);
EDIT: The reason because I pass an arbitrary order of functions from outside the object is because I want to be able to have different combinations of those functions every time. Like for example a choreography, where you can have many dancers able to perform a number of movements, but not always the same, and not the same for everyone. Sorry, this was not specified well enough.