gpt4 book ai didi

javascript - 同时暂停 JavaScript

转载 作者:行者123 更新时间:2023-12-03 08:07:44 24 4
gpt4 key购买 nike

我想暂停但仍同时运行其他代码。例如:

while (true) {
unit++
// wait 3 seconds
}
// do this at the same time
while (true) {
something += 25
// wait 5 seconds
}

最佳答案

这将使单位每三秒增加 1,每五秒增加 25。时间单位以毫秒为单位,因此除以 1000 即可得到以秒为单位的时间,反之亦然。

setInterval(function() { 
unit++;
}, 3000);

setInterval(function() {
something += 25;
}, 5000);

关于javascript - 同时暂停 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34301060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com