I know that the test event will be triggered after scrolling, but the internal process is not very clear. Why is there a return function in it? Which parameter does arguments represent?
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 test = debounce(function(){
console.log("successful")
},250);
window.addEventListener("scroll",test);
I used debugging tools to debug and found that arguments points to event, please help me tell me how it is executed, thank you!