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

我如何在Node.js(Javascript)中等待,我需要暂停一段时间

我如何在Node.js(Javascript)中等待,我需要暂停一段时间

最好的方法是将代码分成多个功能,如下所示:

function function1() {
    // stuff you want to happen right away
    console.log('Welcome to My Console,');
}

function function2() {
    // all the stuff you want to happen after that pause
    console.log('Blah blah blah blah extra-blah');
}

// call the first chunk of code right away
function1();

// call the rest of the code and have it execute after 3 seconds
setTimeout(function2, 3000);

它与 的解决方案相似,但是更加整洁并且易于扩展。

javascript 2022/1/1 18:19:55 有508人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

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

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

请先登录

推荐问题


联系我
置顶