Q1选择题难度 1
1/3
性能优化 · 初级 02
记忆强度
连续触发输入事件后,这段防抖代码最终会打印什么?
function debounce(fn, wait) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), wait);
};
}
const search = debounce(value => console.log(value), 50);
search('a'); // 约 0ms
setTimeout(() => search('ab'), 30);
setTimeout(() => search('abc'), 60);
假设事件循环没有额外的长任务阻塞。