jquery synchronous functions

前端 未结 5 921
攒了一身酷
攒了一身酷 2021-01-05 23:49

Is there a way to run a function after another functions completes? For example:

doSomething();
doSomethingElse();

i only want doSomethingE

5条回答
  •  生来不讨喜
    2021-01-06 00:26

    You may want to do this....

    function doSomething(callback) {
        // code for do some thing
        // now fire off the callback
        if (typeof callback === 'function') {
            callback();
        }
    }
    
    function doSomethingElse() {
    }
    
    doSomething(doSomethingElse);
    

提交回复
热议问题