最好的方法是将代码分成多个功能,如下所示:
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 pre right awayfunction1();// call the rest of the pre and have it execute after 3 secondssetTimeout(function2, 3000);
它与 JohnnyHK 的解决方案相似,但是更加整洁并且易于扩展。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)