您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

应该如何调用3个函数才能一个接一个地执行它们?

应该如何调用3个函数才能一个接一个地执行它们?

doSomething();
doSomethingElse();
doSomethingUsefulThisTime();

doSomething();
doSomethingElse();
doSomethingUsefulThisTime();

function some_3secs_function(value, callback){
  //do stuff
  callback();
}

some_3secs_function(some_value, function() {
  some_5secs_function(other_value, function() {
    some_8secs_function(third_value, function() {
      //All three functions have completed, in order.
    });
  });
});

setTimeout(doSomething, 10);
setTimeout(doSomethingElse, 10);
setTimeout(doSomethingUsefulThisTime, 10);

function executeAsynchronously(functions, timeout) {
  for(var i = 0; i < functions.length; i++) {
    setTimeout(functions[i], timeout);
  }
}

executeAsynchronously(
    [doSomething, doSomethingElse, doSomethingUsefulThisTime], 10);

其他 2022/1/1 18:16:07 有542人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶