当前位置:网站首页>Two ways to write throttling - recently seen
Two ways to write throttling - recently seen
2022-06-29 07:21:00 【You are far from it.】
The first one is
function throttle(fn, delay) {
let timer = 0
return function (fn, delay) {
if (timer) {
return false
}
timer = setTimeout(() => {
fn.apply(this, arguments)
timer = 0
}, delay)
}
}
The second kind
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)
}
}
summary : Two ways of writing , In fact, the effect is a kind of , The first method is simpler in code . It's just if The judgment has changed
边栏推荐
- [translation] [Chapter II ①] mindshare PCI Express technology 3.0
- Shift/space studio "Aurora" project: building a villa in the sandbox metauniverse
- Tree drop-down selection box El select combined with El tree effect demo (sorting)
- JDBC connects to the database and socket sends the client.
- 什么是测试架构师
- Qt 串口编程
- [answer all questions] CSDN question and answer function evaluation
- Testing grpc service with grpcui
- NoSQL数据库介绍
- 利用IPv6实现公网访问远程桌面
猜你喜欢

Message queue avoiding repeated refund by idempotent design and atomic lock

Qt 串口编程

What are the conditions for a high-quality public chain?

CI工具Jenkins之二:搭建一个简单的CI项目

Redis in NoSQL database (4): redis publishing and subscription

Solve the problem that NPM does not have permission

Effective methods for construction enterprises to select smart construction sites
![[QNX Hypervisor 2.2用户手册]6.2.1 Guest之间通信](/img/3d/6a0cde206a09a7ef03038fb99cf532.png)
[QNX Hypervisor 2.2用户手册]6.2.1 Guest之间通信

Testing grpc service with grpcui

mmclassification安装与调试
随机推荐
Illegal forward reference and enums
Testing grpc service with grpcui
mmclassification安装与调试
Introduction to NoSQL database
多模态 —— Learnable pooling with Context Gating for video classification
关联性——相关性分析
Final summary spark
In vscade, how to use eslint to lint and format
机器学习笔记 - 时间序列的混合模型
Markdown 技能树(6):列表
树形下拉选择框el-select结合el-tree效果demo(整理)
VPS是干嘛用的?有哪些知名牌子?与云服务器有什么区别?
软件测试面试如何正确谈论薪资?
Introduction to Ceres Quartet
idea控台中文乱码问题【亲测有效】
QT container class
Redis of NoSQL database (I): Installation & Introduction
Message queue avoiding repeated refund by idempotent design and atomic lock
【科普资料】从科学精神到科学知识的材料
Markdown 技能树(3):标题