当前位置:网站首页>[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);
};
}
边栏推荐
- Introduction and several months' experience of extending the solution thanos of Prometheus
- ACM notes
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- Soft test -- software designer -- database design of afternoon questions
- 2021 programming language ranking summary
- 协程、asyncio、异步编程
- 22/02/15 study notes
- 大型项目中的Commit Message规范化控制实现
- kubernetes删除pod的流程的源码简析
- Es data export CSV file
猜你喜欢
随机推荐
Section Xi. Axi of zynq_ Use of DMA
Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
逆波兰表达式求值<难度系数>
Flutter realizes the function of "shake"
Software design of power control board
asp. Net registration page
Ambari (VI) -- ambari API use
HJ string sort
HJ质数因子
Redis one master multi slave cluster setup
Helloword routine for ROS
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
HJ base conversion
Solving the longest palindrome substring by dynamic programming
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
Porting ucosiii to stm32f429
QT -- communication protocol
Uninstall and reinstall the latest version of MySQL database. The test is valid
Dataset filling data, and the use of rows and columns









