简体   繁体   English

Lodash中油门和反跳之间的区别

[英]Difference between throttle and debounce in lodash

from the lodash documentation: 从lodash文档中:

Throttle 风门

Creates a throttled function that only invokes func at most once per every wait milliseconds 创建一个受限制的函数,每等待一毫秒最多只能调用一次func

Debounce 防抖动

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked 创建一个去抖动的函数,该函数将调用func延迟到自上次调用该去抖动的函数以来的等待毫秒数之后

I am a little bit confused about these two definitions, it sounds that they are similar. 我对这两个定义有些困惑,听起来它们是相似的。

Can someone give us a simple explanation with examples. 有人可以通过示例给我们一个简单的解释。

The lodash docs link to the article Debouncing and Throttling Explained Through Examples . lodash docs链接到文章“ 示例中的反跳和节流”

From that article: 从那篇文章:

The Debounce technique allow us to "group" multiple sequential calls in a single one. 防反跳技术使我们可以将多个顺序调用“分组”在一个调用中。

去抖

By using _.throttle, we don't allow to our function to execute more than once every X milliseconds. 通过使用_.throttle,我们不允许我们的函数每X毫秒执行一次以上。

The main difference between this and debouncing is that throttle guarantees the execution of the function regularly, at least every X milliseconds. 此功能与去抖动之间的主要区别在于,节流阀至少每隔X毫秒就保证有规律地执行该功能。

The article explains the differences clearly using prose and diagrams. 本文使用散文和图表清楚地解释了这些差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM