当前位置:网站首页>[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);
};
}
边栏推荐
猜你喜欢

A single node obtains the lock lock of the order number

SOC timer and interrupt configuration

ACM notes

推荐系统系列精讲(第五讲): 排序模型的调优实践

asp. Net registration page

SOC clock configuration

Introduction and several months' experience of extending the solution thanos of Prometheus

golang gin框架进行分块传输

Section VI UART of zynq

flex布局
随机推荐
8 figures | analyze Eureka's first synchronization registry
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
SOC serial port configuration
自动化测试的生命周期是什么?
Ambari (V) ---ambari integrated Azkaban (valid for personal test)
Section Xi. Axi of zynq_ Use of DMA
Installing redis on Linux
大型项目中的Commit Message规范化控制实现
Introduction and several months' experience of extending the solution thanos of Prometheus
Ice, protobuf, thrift -- Notes
MySQL installation and environment variable configuration
[ thanos源码分析系列 ]thanos query组件源码简析
Es data export CSV file
goland IDE和delve调试位于kubernetes集群中的go程序
Block transmission by golang gin framework
HJ character count
券商注册开户靠谱吗?安全吗?
推荐系统系列精讲(第五讲): 排序模型的调优实践
A single node obtains the lock lock of the order number
Study notes 22/1/19 and 22/1/20