const debounce = (func) => {
return (arg) => {
let timeoutId;
if (timeoutId){
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
func(arg);
}, 1000);
}
}
function hello(name){
console.log("hello " + name);
}
input.addEventListener("input", debounce(hello));
In this example how am I suppose to debounce and call the hello
function with a debounce and the name "Brian"
.
On code line 2 return (arg) => {
what is the code to pass an argument in the variable?
I get that debounce(hello);
calls the debounce function but how am I suppose to pass in a variable so it gets stored in (arg)
?