简体   繁体   中英

Difference between throttle and debounce in lodash

from the lodash documentation:

Throttle

Creates a throttled function that only invokes func at most once per every wait milliseconds

Debounce

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked

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 .

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.

The main difference between this and debouncing is that throttle guarantees the execution of the function regularly, at least every X milliseconds.

The article explains the differences clearly using prose and diagrams.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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