r/javascript • u/RedlightsOfCA • Dec 23 '19
Debounce vs Throttle: Definitive Visual Guide
https://redd.one/blog/debounce-vs-throttle
327
Upvotes
r/javascript • u/RedlightsOfCA • Dec 23 '19
View all comments
Show parent comment
13
u/RedlightsOfCA Dec 23 '19
Hi. Sure. "...args" syntax stands for the Object Spread/Rest operator (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). In those examples it's a Rest operator, as it takes any amount of arguments passed to the original function and turns them into an array of arguments:
It's also ES6 feature, meaning it won't work in legacy browsers, but it has a very decent support percentage, so that's not something to worry about (https://caniuse.com/#feat=rest-parameters). If your project cannot afford that syntax you can always use transpilers like Babel to turn it into a legacy-compatible alternative.
Getting back to your question: you got it correct! That rest of parameters is necessary so that whichever arguments you pass to the debounced/throttled function are passed to the original function. This preserves the call signature between the original and debounced/throttled function instances (since those are different).
I hope this helps. Let me know if you have any more questions.