While learning about Debounce in JS, I've seen 2 different approaches. Is there a difference between calling the callback within the function declaration example vs calling with apply binding within the arrow function example?
function debounce(cb, delay) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId)
timeoutId = setTimeout(() => {
cb(args)
}, delay);
}
}
VS
function debounce(func, delay){
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}