当前位置:网站首页>[JS] - [throttling and anti shake function]
[JS] - [throttling and anti shake function]
2022-06-28 07:53:00 【Interesting learning】
Here's the catalog title
1 Function throttling throttle
throttle.js Create a throttling function , stay wait Maximum execution in milliseconds callback once
function throttle(fn, wait) {
# Define the start time
let start = 0;
# The return result is a function
return function (e) {
// Get the current timestamp
let now = Date.now();
// Judge
if (now - start >= wait) {
// correct this Point to the problem
fn.call(this, e);
// Modify start time
start = now
}
}
}
This method , It can be guaranteed that it will be triggered for the first time , This is followed by a trigger at a specified interval
2 Function anti shake debounce
function debounce(fn, time) {
# Timer variable
var timeId = null;
// Returns a function
return function () {
# Clear timer
clearTimeout(timeId);
# Restart the timer
timeId = setTimeout(() => {
fn.apply(this);
}, time);
};
}
边栏推荐
- Design and implementation of spark offline development framework
- Hj21 simple password
- 推荐系统系列精讲(第五讲): 排序模型的调优实践
- Configuring multiple instances of MySQL under Linux
- Porting ucosiii to stm32f429
- 什么是EC鼓风机(ec blower fan)?
- Software testing and quality final review
- Kubernetes cluster command line tool kubectl
- pip 更新到最新的版本
- Ice, protobuf, thrift -- Notes
猜你喜欢

Soft exam -- software designer -- afternoon question data flow diagram DFD

Kubernetes theoretical basis
![[thanos source code analysis series]thanos query component source code analysis](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[thanos source code analysis series]thanos query component source code analysis

Airflow2.1.1 summary of the pits stepped on in actual combat!!

How to configure DDR3 of dm8148

asp. Net upload image path and image name

Rediscluster cluster mode capacity expansion node

kubelet驱逐机制的源码分析

A single node obtains the lock lock of the order number

Section VII starting principle and configuration of zynq
随机推荐
云原生:云计算技术再次升级 开启全面云开发时代
Configuring MySQL multi instance master-slave synchronization for Linux
Software design of resistance test board
kubernetes集群命令行工具kubectl
协程、asyncio、异步编程
自动化测试的生命周期是什么?
Is it reliable to open a new bond registration account? Is it safe?
SOC timer and interrupt configuration
Rediscluster cluster mode capacity expansion node
pip 更新到最新的版本
Soft exam -- software designer -- afternoon question data flow diagram DFD
HJ字符个数统计
No suspense about the No. 1 Internet company overtime table
Software design of power control board
"Three routines" of digital collection market
Ambari (VIII) --- ambari integrated impala document (valid for personal test)
HJ prime factor
Path alias specified in vite2.9
Es data export CSV file
Kubernetes理论基础