What does _.debounce do?

后端 未结 4 1996
轻奢々
轻奢々 2020-11-28 06:04

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

The Underscore JS documentation for debounce reads as follows:

debounce <

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 06:30

    It holds execution of a function until a timeout is expired. This is to avoid continuous execution of functions when not needed. Beware, since underscore.debounce() relies on complex code. Most of times, a simple "if" statement inside the function is much faster than debounce. You can implement a counter, executing method only each N of iterations, or a timeout, checking that at least a certain amount of milliseconds elapsed.

提交回复
热议问题