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));
在这个例子中,我应该如何使用防抖动并调用带有防抖动的 hello
函数和名称"Brian"
。
在代码第2行中,return (arg) => {
怎样传递参数到变量中?
我知道 debounce(hello);
调用了防抖函数,但是我应该如何传递一个变量,以便它被存储在 (arg)
中?