当前位置:网站首页>Anti shake and throttling
Anti shake and throttling
2022-04-23 08:05:00 【Pen drawing Acacia】
Shake proof : The problem to be solved is when an event is triggered multiple times within a time interval , It's only going to be executed once
throttle : The solution is to reduce the trigger frequency for a period of time
1: The function will only trigger once in a specified time , Specific implementation method
When the function is triggered for the first time , Delay delay Time execution , If in delay The function is triggered again within a time period , Then start over
timing
If delay The function is not triggered within the time period , Then execute the function
function bunde(fn ,depaly)
{
let timetar=null;
return function()
{
if(timetar)
{
clearTimeout(timetar);
}
timetar=setTimeout(fn,depaly);
}
}
throttle :
The problem with anti shake is , Continuously trigger events in a short time , Callback functions never execute .
The idea of saving money : Continuously trigger events in a short time , The callback function will only execute within the specified interval .
function throttle(fn, delay) {
let timer = null;
return function() {
if (timer) return false
timer = setTimeout(() => {
fn()
timer = null
}, delay)
}
}

版权声明
本文为[Pen drawing Acacia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624332804.html
边栏推荐
- Intranet penetration series: pingtunnel of Intranet tunnel
- A programmer who works four hours a day
- TA notes of Zhuang understand (VII) < Lambert + Phong + shadow + 3evcolor + Ao >
- [NLP notes] preliminary study on CRF principle
- Research on system and software security (2)
- Ribbon启动流程
- 一文了解系列,对web渗透的常见漏洞总结(持续更新)
- 数据库之MySQL——基础篇
- String self generated code within a given range
- 第四章 无形资产
猜你喜欢

When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.

Chapter V investment real estate

Unity get real geographic map application terrain notes

数据库之MySQL——基本常用查询命令

Go语学习笔记 - Slice、Map | 从零开始Go语言

Intranet penetration series: icmpsh of Intranet tunnel

《内网安全攻防:渗透测试实战指南》读书笔记(八):权限维持分析及防御

Ribbon启动流程

Attack and defense world misc questions 1-50

Simplify exporting to SVG data files and all images in SVG folder
随机推荐
Essays (updated from time to time)
TA notes of Zhuang understand (VII) < Lambert + Phong + shadow + 3evcolor + Ao >
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
C problem of marking the position of polygons surrounded by multiple rectangles
一文了解系列,对web渗透的常见漏洞总结(持续更新)
TA notes of Zhuang understand (zero) < bedding and learning methods >
Intranet penetration series: icmptunnel of Intranet tunnel (by master dhavalkapil)
A programmer who works four hours a day
内网渗透系列:内网隧道之pingtunnel
【编程实践/嵌入式比赛】嵌入式比赛学习记录(一):TCP服务器和web界面的建立
strcat()、strcpy()、strcmp()、strlen()
KVM安装部署
[problem solving] vs2019 solves the problem that the EXE file generated by compilation cannot be opened
DVWA靶场练习
RAID0和RAID5的创建和模拟RAID5工作原理
Personality charm of high paid it workers
What's new in. Net 5 NET 5
Go语学习笔记 - 数组 | 从零开始Go语言
CTF attack and defense world brush questions 51-
内网渗透系列:内网隧道之icmptunnel(DhavalKapil师傅的)