How to implement debounce with JavaScript
This article mainly introduces JavaScript how to achieve debounce, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Debounce (anti-shaking)
The function will only be executed once within n seconds after triggering the high frequency time, and if the high frequency time is triggered again within n seconds, the time will be recalculated.
Const debounce = (fn, time) = > {let timeout = null; return function () {clearTimeout (timeout) timeout = setTimeout (() = > {fn.apply (this, arguments);}, time);}}
Anti-dithering is often used for users to save request resources for search input. Anti-dithering is only triggered once when window triggers resize events.
Thank you for reading this article carefully. I hope the article "how to achieve debounce in JavaScript" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!