function debounce(fn, delay) {
let timerId = null;
return function (...args) {
if (timerId) {
clearTimeout(timerId);
timerId = null;
}
timerId = setTimeout(() => {
fn(...args);
}, delay)
}
}
老师,我没有把timerid绑定在fn上 也没有放在debounce 函数外部,而是绑定那里,我斗胆觉得老师把timerid绑定在fn上会污染fn函数,而我这个即起到和老师那个同样的作用又没有污染fn函数,你这样的写法有什么缺点吗?
展开