// 防抖函数和节流函数, 使用方法antiShaking(() => { // 执行动作 // }) let timer = null; //time用来控制事件的触发 // 防抖 export function antiShaking(functionItem, delay = 500) { //防抖语句 if(timer !== null){ clearTimeout(timer); } timer = setTimeout(() => { console.log(5464, functionItem) functionItem() //这里的this指向的是input }, delay) } // 节流 export function throttle(fn, delay = 500) { if(timer) return timer = setTimeout(() => { fn.apply(this,arguments) timer = null }, delay) }
标签:防抖,节流,timer,delay,functionItem,null From: https://www.cnblogs.com/yan122/p/17034356.html