Run a function inside a function?

I’m using setInterval to pause between functions, called, “setText1”, “setText2”, etc… I’m using keyframes to determine when to start running the next function, but I know there’s an easier way to do it.

What i’d like to do is just have one keyframe that runs all the functions in order, kind of like this:


function setText1(){
// do stuff here
 new TimeOut(this, "setText2", 500);
}
setText1();
 
function setText2(){
// do stuff here
 new TimeOut(this, "setText3", 500);
}
setText2();
 
function setText3(){
// do stuff here
 new TimeOut(this, "setText4", 500);
}
setText3();

…as you can see, it will run the first function, wait, run the next one, wait, etc…

My question would be: How can I create my function called ‘TimeOut’ that will run whatever function-name is passed to it? Can you run a function within a function??

Please help!