I found the following code online and I'm trying to implement it to work with a resize event listener and am struggling to understand the intricacies of how it works. Would someone be willing to break it down into speak that someone with only 3 months experience of JS/Jquery would understand? A few pointers as to what I'm struggling with (which is most of it, but I'll define the really perplexing parts) where is "arguments" or the variable "args" that it's value has been assigned to defined? How does one pass "immediate" into the debounce function. etc. etc.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this,
args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
var debounceHeightSet = debounce(function() {
numHeightset();
}, 250);