javascript (用setTimeout而非setInterval)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

javascript (用setTimeout而非setInterval)

  2020-05-13 我要评论
复制代码 代码如下:

var num = 0;
var max = 10;
function incrementNumber() {
num++;
//if the max has not been reached, set another timeout
if (num < max) {
setTimeout(incrementNumber, 500);
} else {
alert(“Done”);
}
}
setTimeout(incrementNumber, 500);

如果用setInterval 可能出现 下次调用会在前一次调用前调用 (

True intervals are rarely used in production environments because it ' s possible that one interval will begin before the previous one has finished executing)

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们