当前位置:网站首页>Throttling and anti shake
Throttling and anti shake
2022-06-11 06:28:00 【Saucey_ six】
Throttling and anti shake
effect : Are born to save computer resources , That is, it belongs to optimization
principle : Both usesetTimeoutTo store the functions to be executed , It is very convenient to use its delay mechanism to determine the appropriate function trigger time .
throttle
Definition : Only one task can be executed within the specified time interval
scene : Lazy loading when loading pictures ,scroll Scroll bar timing
Realization :
function throttle(fn, interval) {
let canRun = true;
return function () {
if (!canRun) return;
canRun = false
setTimeout(() => {
fn.apply(this, arguments)
canRun = true
}, interval)
}
}
Shake proof
Definition : When the task is triggered frequently , Only when the interval of task triggering exceeds the specified interval , The task will be performed , Its timing has an update
scene : Judgment of user name input
Realization :
function debounce(fn, interval) {
let timeout = null;
return function () {
clearTimeout(timeout)// Clear the time of the previous trigger
timeout = setTimeout(() => {
fn.apply(this, arguments)
}, interval)
}
}
end !
边栏推荐
- jenkins-不同风格的项目构建
- Use of constructors
- autojs,读取一行删除一行,停止自己外的脚本
- Review XML and JSON
- Examinelistactivity of Shandong University project training
- JS two methods to determine whether there are duplicate values in the array
- Squid agent
- Detailed installation instructions for MySQL
- Growth Diary 01
- Transfer Learning
猜你喜欢

Learn C language well from keywords

This point of arrow function

Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)

C语言大战“扫雷”
![Handwritten promise [05] - exception capture of promise method and optional parameters of then method implementation](/img/e7/87069f921ae003511e32b23653703c.jpg)
Handwritten promise [05] - exception capture of promise method and optional parameters of then method implementation

Metasploitabile2 target learning
![[]==![]](/img/65/ab724c74b080da319ed5c01c93fdb7.png)
[]==![]

Stock K-line drawing

PHP laravel8 send email

CCS method of installing compiler
随机推荐
Record the first data preprocessing process
Transfer Learning
Human gene editing technology and ethical issues behind it [personal view, for reference only]
Handwritten promise [05] - exception capture of promise method and optional parameters of then method implementation
Vulhub 8.1-backdoor vulnerability recurrence
EasyGBS接入的设备视频直播突然全部无法播放是为什么?数据库读写不够
Graphsage paper reading
Handwritten a message queue in two ways
JS two methods to determine whether there are duplicate values in the array
FPGA interview notes (II) -- synchronous asynchronous D flip-flop, static and dynamic timing analysis, frequency division design, retiming
Simple knapsack problem
Simple understanding of XML and JSON
fatal: refusing to merge unrelated histories
Training and testing of super score model in mmediting
FPGA Design -- ping pong operation implementation and Modelsim simulation
QT socket setting connection timeout
FPGA面试题目笔记(三)——跨时钟域中握手信号同步的实现、任意分频、进制转换、RAM存储器等、原码反码和补码
Convert text label of dataset to digital label
使用Meshlab对CAD模型采样点云,并在PCL中显示
LeetCodeT526