当前位置:网站首页>type of timer
type of timer
2022-07-31 15:22:00 【I must win this time】
One. Timer setTimeout, setInterval
(1) setTimeout
setTimeout(() => {console.log('It's time to execute me');}, timeout);This timer will only run once
Code:
setTimeout(() => {console.log('It's time to execute me');}, 2000);
You can see the content inside after 2s hit.
Please continue reading
(2) setInterval
setInterval(() => {console.log('It's time to execute me');}, interval);Code:
setInterval(() => {console.log('It's time to execute me');}, 2000);
It will be executed every 2s.
2. Clear timer clearTimeout
(1) clearTimeout(timer name)
let timer = setTimeout(() => {console.log('It's time to execute me');}, 2000);clearTimeout(timer)As you can see, nothing is printed in the console.
(2)clearInterval(timer name)
let timer1 = setInterval(() => {console.log('It's time to execute me');}, 2000);setTimeout(() => {clearInterval(timer1)}, 6000);
What you can see is that it is executed three times, it is no longer executed, and it has been cleared at this time.
To clear a timer, first give it a name.and finally clear it.
边栏推荐
- 更新数据表update
- 模板与泛型编程值typelist实现
- NC | 斯坦福申小涛等开发数据可重复分析计算框架TidyMass
- ASP.NET Core 产生连续 Guid
- 763.划分字母区间——之打开新世界
- The normal form of the database (first normal form, second normal form, third normal form, BCNF normal form) "recommended collection"
- Node实现数据加密
- JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
- Emmet 语法
- Excel quickly aligns the middle name of the table (two-word name and three-word name alignment)
猜你喜欢
随机推荐
Node实现数据加密
C语言”三子棋“升级版(模式选择+AI下棋)
乡村基冲刺港交所:5个月期内亏2224万 SIG与红杉中国是股东
7. Summary of common interview questions
01 邂逅typescript,环境搭建
《微信小程序-进阶篇》Lin-ui组件库源码分析-Icon组件
Web自动化实战——Selenium4(自动化测试环境的搭建)
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
NC | 中国农大草业学院杨高文组揭示发现多因子干扰会降低土壤微生物多样性的积极效应...
Doing things software development - the importance of law and understanding of reasonable conclusions
Delete the disk in good condition (recovery partition)
Selenium自动化中无头浏览器的应用
修改SQL语言实现Mysql 多表关联查询优化
OPPO在FaaS领域的探索与思考
工程力学复习资料
R language test whether the sample conforms to normality (test whether the sample comes from a normally distributed population): shapiro.test function tests whether the sample conforms to the normal d
TRACE32——C源码关联
TRACE32——基于SNOOPer的变量记录
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
使用 PyTorch 检测眼部疾病









