Talking about the difference between _.throttle and _.debounce in underscore.js [turn]

Source: Internet
Author: User

Read the article from: Https://blog.coding.net/blog/the-difference-between-throttle-and-debounce-in-underscorejs

Usage Scenarios

These two functions can be taken into account as long as they are involved in a continuous event or frequency control-related application, such as:

    • Game shooting, KeyDown events
    • Text input, AutoComplete, KeyUp events
    • Mouse movement, MouseMove events
    • DOM element dynamic positioning, resize and scroll events for window objects

There's a metaphor in the article.

    • throttleStrategy of the elevator. Ensure that if the elevator first person comes in, 15 seconds after delivery on time, do not wait. If there is no one, then standby.
    • debounceStrategy of the elevator. If someone comes in the elevator, wait 15 seconds. If another person comes in, 15 seconds waits for a re-timer until 15 seconds expires and the shipment begins.

The commentary is also wonderful:

Throttle: Trigger-last action execution time greater than limit time, execute action, record execution time
Debounce: Trigger-record trigger time-last action trigger time greater than limit time-perform action

-----------

You can see it.

throttle: Timed fixed point

Debounce: for deferred processing

Talking about the difference between _.throttle and _.debounce in underscore.js [turn]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.