当前位置:网站首页>节流的两种写法-最近看到的这种写法
节流的两种写法-最近看到的这种写法
2022-06-29 06:38:00 【你还差的远呢。】
第一种
function throttle(fn, delay) {
let timer = 0
return function (fn, delay) {
if (timer) {
return false
}
timer = setTimeout(() => {
fn.apply(this, arguments)
timer = 0
}, delay)
}
}
第二种
function throttle(fn, delay) {
let flag = true
return function (fn, delay) {
if (!flag) {
return false
}
flag = false
setTimeout(() => {
fn.apply(this, arguments)
flag = true
}, delay)
}
}
总结: 两种写法,实际上效果是一种的,第一种写法代码上更简洁一些。只是 if 里面的判断变了而已
边栏推荐
- QT custom bit operation class
- QT STL type iterator
- Configuring MySQL 5.7 and 8 under CentOS
- Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2
- NoSQL数据库之Redis(一):安装 & 简介
- MIPS指令集与简要分析
- UVM authentication platform
- Database - Synonyms
- [when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]
- Differences between JSON objects and JSON strings
猜你喜欢

UVM authentication platform

Draw multiple ROC curves on a graph

NoSQL数据库之Redis(四):Redis新数据类型

Json tobean

国内代码托管中心- 码云

Two methods for preorder traversal of binary tree

数字ic设计——UART

YGG cooperated with Web3 platform leader to empower the creative community with Dao tools and resources

IDEA 集成 码云

转:侯宏:企业数字化转型的关键不是技术,而是战略
随机推荐
Exploring the depth of objects in JVM series
Idea integrated code cloud
Testing grpc service with grpcui
Configuring MySQL 5.7 and 8 under CentOS
Qt 程序打包发布-windeployqt工具
As a qualified network worker, you must master DHCP snooping knowledge!
. Net core + DDD basic layering + project basic framework + personal summary "suggestions collection"
Database - Synonyms
uva10859
. NETCORE uses redis to limit the number of interface accesses
Qt STL类型迭代器
The realization of changing pop-up background at any time
Webrtc series - 8-connectivity detection for network transmission
利用Jsonp跨域请求数据
[answer all questions] CSDN question and answer function evaluation
【翻译】e-Cloud。使用KubeEdge的大规模CDN
What are the conditions for a high-quality public chain?
Markdown 技能树(9):表格
[translation] [Chapter II ①] mindshare PCI Express technology 3.0
Multimodal learning pooling with context gating for video classification