javascript (用setTimeout而非setInterval)

时间:2011-12-28    点击:112   
复制代码 代码如下:

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)
js当一个变量为函数时 应该注意的一点细节小结
为JavaScript类型增加方法的实现代码(增加功能)
javaScript 利用闭包模拟对象的私有属性
Jquery中删除元素的实现代码
JavaScript中两个感叹号的作用说明
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved