jquery synchronous functions

前端 未结 5 922
攒了一身酷
攒了一身酷 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:16

    There's no way to enforce this explicitly per se, but one idea is to have doSomething() return a value that doSomethingElse() accepts as a parameter:

      retval = doSomething();
      doSomethingElse(retval);
    

    that way at least you prevent somebody from calling doSomethingElse() without at least supplying the argument it needs... of course, whether they get that argument from calling doSomething() is another issue. But this is a start.

    Idea lifted from Code Complete.

提交回复
热议问题