Intervals

 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)

Timeouts

 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)

  Note that when you're using timeouts, it is unnecessary to track the timeoutID, because the execution will stop on its own and continue only if another timeout is set. The pattern is considered a best practice for setting intervals without actually using intervals. True intervals are rarely used in production environments because the time between the end of one interval and the beginning of the next is not necessarily guaranteed, and some intervals may be skipped. Using timeouts, as in the preceding example, ensures that can't happen. Generally speaking, it's best to avoid intervals.

最新文章

  1. 使用Microsoft Roslyn提取C#和VB.NET源代码中的字符串常量
  2. Sort Colors [LeetCode]
  3. leetcode 1_2_3_7
  4. centos 服务开机启动设置
  5. Android开源项目汇总【转】
  6. [CF353C]Find Maximum(贪心)
  7. c++关于接口机制和不完全类型的小问题
  8. Android的Intent作用
  9. 使用CSS修改HTML5 input placeholder颜色( 转载 )
  10. 文件IO 练习题
  11. linux操作系下RAR的使用
  12. linux 文件系统操作()
  13. devops工具-Ansible基础
  14. 迭代器与泛型for
  15. python-运算符重载
  16. 弱也有弱的ACM经历
  17. C#如何使用VS2010与SQL2008建立链接及初步调用(转)
  18. js 解决图片居中问题
  19. Hibernate的查询方式汇总
  20. 下拉框多选实现回显及sql

热门文章

  1. shutdown immediate 持久无法关闭数据库之解决方案
  2. Internet层协议下IP协议
  3. fullpage.js最后一屏不满一屏时,滚动方式
  4. Hadoop-No.6之文件在HDFS中的位置
  5. lombok使用及常用注解
  6. js的DOM操作整理(整理)
  7. 归类常用控件GroupBox、TabControl、Expander
  8. JVM(九),垃圾回收回收算法
  9. linux shell 值coredump suid_dumpable和 gdb解析coredump文件
  10. Python中很少见的用法