当前位置:网站首页>Implement the throttling de dithering function
Implement the throttling de dithering function
2022-06-24 03:29:00 【HZFEStudio】
Complete high frequency question bank warehouse address :https://github.com/hzfe/awesome-interview
Complete high frequency question bank reading address :https://febook.hzfe.org/
throttle
1. Basic concepts
throttle(func, wait)
Every time wait At most once in milliseconds func.
2. Application scenarios
- Real time association when entering the search box .
- monitor scroll Event calculation location information .
3. flow chart
4. Write code
function throttle(func, wait) {
let lastTime = 0;
let timer = null;
return function () {
if (timer) {
clearTimeout(timer);
timer = null;
}
let self = this;
let args = arguments;
let nowTime = +new Date();
const remainWaitTime = wait - (nowTime - lastTime);
if (remainWaitTime <= 0) {
lastTime = nowTime;
func.apply(self, args);
} else {
timer = setTimeout(function () {
lastTime = +new Date();
func.apply(self, args);
timer = null;
}, remainWaitTime);
}
};
}To shake
1. Basic concepts
debounce(func, wait)
Delay since last trigger wait Millisecond call func.
2. Application scenarios
- When registering, check whether the user name is occupied after entering it .
- monitor resize Event calculation size information .
3. flow chart
4. Write code
function debounce(func, wait) {
let timer = null;
return function () {
if (timer) {
clearTimeout(timer);
timer = null;
}
let self = this;
let args = arguments;
timer = setTimeout(function () {
func.apply(self, args);
timer = null;
}, wait);
};
}边栏推荐
- TRTC audio quality problem
- How to access the cloud game management server? Which cloud game management server can I choose?
- How to access the server through the fortress machine? What's the use of the fortress machine?
- What is elastic scaling in cloud computing? What are the main applications of elastic scaling in cloud computing?
- golang with script
- Hunan data security governance Summit Forum was held, and Tencent built the best practice of government enterprise data security
- Chapter 5: key led demo case of PS bare metal and FreeRTOS case development
- Why do I need a code signing certificate? Where can I get a code signing certificate?
- Clickhouse optimize table comprehensive analysis
- How to handle the uplink and downlink silence of TRTC
猜你喜欢
![[summary of interview questions] zj5](/img/d8/ece82f8b2479adb948ba706f6f5039.jpg)
[summary of interview questions] zj5

Sorting out of key vulnerabilities identified by CMS in the peripheral management of red team (I)

Community pycharm installation visual database

Simple and beautiful weather code

Get to know MySQL database
![[summary of interview questions] zj6 redis](/img/4b/eadf66ca8d834f049f3546d348fa32.jpg)
[summary of interview questions] zj6 redis

On Sunday, I rolled up the uni app "uview excellent UI framework"

Ar 3D map technology

QT creator tips
随机推荐
Grp: how to gracefully shutdown a process?
An example of SPM manual binding execution plan
How much is a fortress machine? Why do you need a fortress machine?
System library golang Org/x/time/rate frequency limiter bug
Is the cloud desktop server highly required for installation and configuration? Is cloud desktop easy to use?
Which domestic cloud desktop server is good? What are the security guarantees for cloud desktop servers?
Why install code signing certificate to scan and eliminate virus software from security
Why should I change my PC to a cloud desktop server? What are the characteristics of this server?
Grand summary of boutique idea plug-ins! Worth collecting
Double 11 will arrive soon. Is your website ready?
Chapter 4: LED flash case of PS bare metal and FreeRTOS case development
Understand Devops from the perspective of leader
How to pair cloud game servers? Is the cloud game server expensive?
Concise and practical time code
Sinclair radio stopped broadcasting many TV stations, suspected of being attacked by blackmail software
Shopee Clickhouse cold and hot data separation storage architecture and Practice
Lua language development, esp8266 access to Bafa cloud, mqtt and TCP protocols
How to solve the problem of easycvr playing the total recording time in the specified time period?
Grpc: how to make grpc provide swagger UI?
Tencent Mu Lei: real scene 3D linking industrial Internet and consumer Internet