原来clearInterval和 clearTimeout可以互用
来源:互联网 发布:计算机编程有什么种类 编辑:程序博客网 时间:2024/06/03 08:45
setInterval和setTimeout返回的是一个整数ID。从技术上来说clearInterval和clearTimeout是可以互用的,如下所示。不过这样做会造成语义上的歧义,因此并不建议。
var timer = setInterval(function() { console.log('hello world');}, 1000);// clearInterval(timer);clearTimeout(timer); // 这样也可以
MDN 关于setInterval的解释
It may be helpful to be aware that setInterval() and setTimeout() share the same pool of IDs, and that clearInterval() and clearTimeout() can technically be used interchangeably. For clarity, however, you should try to always match them to avoid confusion when maintaining your code.
阅读全文
1 0
- 原来clearInterval和 clearTimeout可以互用
- js计数器方法:setInterval()和clearInterval();setTimeout()和clearTimeout()
- HTML DOM中setInterval()和clearInterval()、setTimeout()和clearTimeout()
- js计数器方法setInterval()、clearInterval()、setTimeout()和clearTimeout()
- setTimeout,clearTimeout与setInterval,clearInterval
- javascript 中setTimeout()和clearTimeout()及setInterval()和clearInterval()的用法
- Settimeout 设置以后,可以用cleartimeout清除。
- js中setInterval/clearInterval与setTimeout/clearTimeout
- call(),apply(),callee,caller,cookie方法,setInterval(),clearInterval(),setTimeout() ,clearTimeout()
- js定时器用法详解——setTimeout()、setInterval()、clearTimeout()、clearInterval()
- SetTimeOut()和ClearTimeout()
- setTimeout和clearTimeout
- clearTimeout
- setInterval和clearInterval 讲解
- setInterval和clearInterval 讲解
- setInterval和clearInterval 讲解
- setInterval和clearInterval
- setInterval和clearInterval(转)
- 微信禁止微信自带浏览器变化字体
- HttpURLConnection 发送 文件和字符串信息
- 图的邻接矩阵与邻接表存储方式及优缺点对比
- Python正则表达式指南
- PHP设计模式之单例模式
- 原来clearInterval和 clearTimeout可以互用
- Shell 彩色进度条
- 控件大出父容器完全展示
- Hibernate框架04
- 【2017-7-11】BZOJ3673 可持久化并查集
- 队列----定义和实现
- 一个协程的使用示例(走走停停效果)
- 全球最好的IT企业文化 :Netflix 企业文化
- 再谈 Signal 与 APC 实现