Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

javascript - JavaScript中是否有睡眠/暂停/等待功能? [重复](Is there a Sleep/Pause/Wait function in JavaScript? [duplicate])

Possible Duplicate:

(可能重复:)
What is the JavaScript version of sleep()?

(什么是sleep()的JavaScript版本?)

Is there a JavaScript function that simulates the operation of the sleep function in PHP — a function that pauses code execution for x milliseconds, and then resumes where it left off?

(是否有一个JavaScript函数模拟PHP中sleep函数的操作 - 一个暂停代码执行x毫秒的函数,然后从它停止的地方恢复?)

I found some things here on Stack Overflow, but nothing useful.

(我在Stack Overflow上找到了一些东西,但没什么用处。)

  ask by Richard translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to re-factor the code into pieces.

(您需要将代码重新分解为多个部分。)

This doesn't stop execution, it just puts a delay in between the parts.

(这不会停止执行,只会在各部分之间造成延迟。)

function partA() {
  ...
  window.setTimeout(partB,1000);
}

function partB() {
   ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...