适用于搜索联想等
// 在delay时间段内如果重复执行,则保留最后一次结果
function debound(Fn, delay = 500){
let timer = null;
return function(...args){
if(timer){
clearTimeout(timer);
}
timer = setTimeout(() => {
Fn.apply(this, args);
}, delay);
}
}
window.addEventListener('keyup', debound(function(){
console.log('this', this);
console.log(123);
}, 600));