当前位置:网站首页>[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);
};
}
边栏推荐
- Evaluation of inverse Polish expression < difficulty coefficient >
- No suspense about the No. 1 Internet company overtime table
- 7-2 Finnish wooden chess structure Sorting
- 推荐系统系列精讲(第五讲): 排序模型的调优实践
- Makefile
- Localization SoC development plan
- Sword finger offer|: linked list (simple)
- DBeaver 22.1.1 发布,可视化数据库管理平台
- Redis one master multi slave cluster setup
- Source code analysis of kubernetes' process of deleting pod
猜你喜欢

22/02/15 study notes

Recommended system series (Lecture 5): Optimization Practice of sorting model

Online WPS tool

What is EC blower fan?

kubernetes集群命令行工具kubectl

剑指Offer||:链表(简单)

Porting ucosiii to stm32f429

Kubernetes理论基础

Static resource compression reduces bandwidth pressure and increases access speed

Airflow2.1.1 summary of the pits stepped on in actual combat!!
随机推荐
MySQL installation and environment variable configuration
HJ delete the character with the least number of occurrences in the string
Section VI UART of zynq
HJ成绩排序
Airflow2.1.1 summary of the pits stepped on in actual combat!!
[ thanos源码分析系列 ]thanos query组件源码简析
Configuring multiple instances of MySQL under Linux
ACM notes
8 张图 | 剖析 Eureka 的首次同步注册表
Study notes 22/1/11
Ambari (VI) -- ambari API use
Spark 离线开发框架设计与实现
分析 NFT 项目的 5 个指标
Porting ucosiii to stm32f429
Ice, protobuf, thrift -- Notes
LeetCode之三步问题
2021 programming language ranking summary
Configuring MySQL multi instance master-slave synchronization for Linux
数字藏品市场“三大套路”
PLC -- Notes