sequencing function calls in javascript - are callbacks the only way?

后端 未结 5 541
谎友^
谎友^ 2021-02-03 11:25

I read through various threads like this one for example.

But it really escapes me how to accomplish the following:

I have 4 functions, and want them happen one

5条回答
  •  北海茫月
    2021-02-03 11:58

    If I'm using callbacks, my working solution now looks like this:

        one(two);
        function one(callb){
            console.log('1');
            callb(three);
        }
        function four(){
            console.log('4');
        }
        function two(callb){
            console.log('2');
            callb(four);
        }
        function three(callb){
            console.log('3');
            callb();
        }
    

    I find that hideous. How am I supposed to keep track of this stuff if there is more than 2-3 sequences? Shudder...

提交回复
热议问题