当前位置:网站首页>Attention should be paid to the first parameter of setTimeout
Attention should be paid to the first parameter of setTimeout
2022-07-27 03:10:00 【Wuuconix】
setTimeout The first parameter should pay attention to
The first parameter should be a function , Instead of a function call .
setTimeout(console.log('2333'), 1000)
Such a statement seems to have no problem ,1000 In milliseconds console.log(‘23333’). But it's totally wrong , In the browser you will find , He didn't wait 1000 millisecond , And directly output .
And in the node Will be output immediately 23333 Report a mistake later .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PRFJwWj8-1657604281201)(http://qiniu.wuuconix.link/image-20220712132906968.png)]](/img/58/0b7bc7f04be0276f92cd05fbfd12d8.png)
The error message is Callback must be a function. Received undefined. We know ,console.log The return value of undefined.
therefore console.log('23333') It looks like a function here , And he is actually a undefined.
So we can have two solutions , One is to pass in parameters later .
setTimeout(console.log, 1000, '23333')
This is troublesome when there are many parameters , It's not easy to understand .
A better way is to wrap the call statement in an arrow function .
setTimeout(() => console.log('23333'), 1000)
This is beautiful and easy to understand .
边栏推荐
- Debezium系列之:记录从库服务器挂掉后binlog文件无法恢复,任务切换到主库并保证数据不丢失的方法
- 红宝书第四版的一个错误?
- Use the most primitive method to manually implement the common 20 array methods
- 阿里云解决方案架构师张平:云原生数字化安全生产的体系建设
- IDEA 连接数据库查询数据后控制台表头中文乱码的解决方法
- 论构造函数的原型是谁
- 云开发寝适闹钟微信小程序源码
- How to visit the latest version of burpsuite pro in vain
- B-树的应用以及添加和删除操作
- Thread.Sleep(0)的作用
猜你喜欢

Plato Farm全新玩法,套利ePLATO稳获超高收益

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

抖音服务器带宽有多大,才能供上亿人同时刷?

Concept of data asset management

What did kubedmin do?

万字长文,带你搞懂 Kubernetes 网络模型

The EXE compiled by QT is started with administrator privileges

阿里云技术专家杨泽强:弹性计算云上可观测能力的构建

Play a parallel multithreaded mcu-mc3172

Inftnews | ggac and China Aerospace ases exclusively produce "China 2065 Collection Edition"
随机推荐
Favicon网页收藏图标在线制作PHP网站源码/ICO图片在线生成/支持多种图片格式转换
Pyqt5 use pyqtgraph to draw dynamic scatter chart
window对象的常见事件
基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
Role of thread.sleep (0)
IDEA 连接数据库查询数据后控制台表头中文乱码的解决方法
Thread.Sleep(0)的作用
Kubernetes Dashboard 部署应用以及访问
Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
Zhang Ping, Alibaba cloud Solution Architect: system construction of cloud native digital safety production
Concept of data asset management
OpenTelemetry 在服务网格架构下的最佳实践
调用JShaman的Web API接口,实现JS代码加密。
196. 删除重复的电子邮箱
How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
day6
素因子分解--C(gcc)--PTA
After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized
Use of formdata
setTimeout第一个参数应该注意的地方