Saturday, June 1, 2024
122
rated 0 times [  127] [ 5]  / answers: 1 / hits: 44944  / 11 Years ago, wed, april 10, 2013, 12:00:00

A project I've been working on uses _.debounce().



The Underscore JS documentation for debounce reads as follows:




debounce _.debounce(function, wait, [immediate])



Creates and returns a new debounced version of the passed function
that will postpone its execution until after wait milliseconds have
elapsed since the last time it was invoked.




This obviously assumes that anyone who wants to know what debounce() does, already knows what 'debounce' means.



What does debounce actually do?


More From » underscore.js

 Answers
14

Basically it throttles calls so if it is called more than once in a short period of time, only one instance will be called.



Why would you use it?



Events like window.onresize fire multiple times in rapid succession. If you need to do a lot of calculations on the new position, you would not want to fire the calculations multiple times. You only want to fire it when the user has finished the resizing event.


[#78990] Tuesday, April 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grayson

Total Points: 36
Total Questions: 113
Total Answers: 95

Location: Tonga
Member since Fri, Aug 21, 2020
4 Years ago
grayson questions
;