let counter =0;
const getData =()=>{
console.log('api called');
counter++;
console.log("counter",counter);
}
const debounce = function(fn,de){
let timer;
return function(){
let context = this,args=arguments;
console.log("context",this);
console.log("arguments",args);
clearInterval(timer);
timer = setTimeout(()=>{
fn.apply(context,arguments)
},de);
}
}
const betterFunction = debounce(getData,3000);
betterFunction();
A simple console log of the context in the above code prints window ?Why is it so and another thing is that why context has passed to the inner function when context is actually a window .