当前位置:网站首页>Throttling and anti shake
Throttling and anti shake
2022-06-24 00:01:00 【qq_ fifty-three million two hundred and eighty thousand eight h】
The purpose of throttling and anti shake :
To limit the frequency of function execution , The trigger frequency of the optimization function is too high, so the response speed can not keep up with the trigger frequency , Prevent delay caused by frequently triggering the same event in a short time , The phenomenon of feigning death or being stuck .The difference between throttling and anti shake :
throttle : There is an incident A Timer set , So in delay Trigger before , Will only trigger once .
Shake proof : If in delay Re trigger before , Then the timer will continue to re time , Finally, it will be executed after the last time , For those requiring real-time response , Throttling should be used .
3: Example
// throttle `
function throttle(fun,delay){
let flag = true;
return function(){
if(!flag){
return;
}
flag = false;
setTimeout(()=>{
fun.apply(this,arguments);
flag = true;
},delay)
}
}
function output(){
console.log(' throttle ',Math.random());
}
// Shake proof
function antiShake(fun,delay){
let timeout = null;
return function(e){
clearTimeout(timeout);
timeout = setTimeout(()=>{
fun.apply(this,argument);
},delay)
}
}
function play(){
console.log(' Shake proof ');
}
边栏推荐
- 数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?
- .NET 中的 Worker Service 介绍
- List<? Extensions T > and list <? Super T > difference
- Smart doc + Torna compatible version
- [proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
- 不同物体使用同一材质,有不同的表现
- How to use data warehouse to create time series
- 图扑软件智慧风电:数字孪生 3D 风机智能设备运维
- 2021-11-23: Regulations: l[1] corresponds to a, l[2] corresponds to B, l[3] corresponds to C
- Generative countermeasure networks (Gans) and variants
猜你喜欢

Under the background of aging, the comprehensive energy efficiency management platform escorts hospitals

Cloud native architecture (05) - Application Architecture Evolution

fatal: The upstream branch of your current branch does not match the name of your current branch.

Application of acrel-3000web power management system in Duba Expressway

Three cool and coquettish bottom navigation

生成所有可能的二叉搜索树

Loop caused by add of sublist in list

电子元器件行业B2B交易管理系统:提升数据化驱动能力,促进企业销售业绩增长

生成式对抗网络(GANs)及变体

Save: software analysis, verification and test platform
随机推荐
log Network Execution Time
Solve the problem of project dependency red reporting
Generate all possible binary search trees
Revit API:明细表 ViewSchedule
数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?
Comment utiliser l'entrepôt de données pour créer une table de synchronisation
[technical grass planting] use the shared image function to realize the offline switching from CVM to LH
暑假第一周
电子元器件行业B2B交易管理系统:提升数据化驱动能力,促进企业销售业绩增长
Return, const, volatile keywords
Nice input edit box
How to take the PMP Exam agile on June 25? Share your troubles
Perfectionist win10 installation guide
Generative countermeasure networks (Gans) and variants
docker redis集群配置
测试 - 用例篇 - 细节狂魔
I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...
UART协议时序总结
PMP Exam related calculation formula summary! Must see before examination
Cross domain issues of the new version of Google browser