// 防抖 export function debounce(fn, wait = 3000) { let timer = null; return function () { console.log(wait) let args = arguments; let that = this; if (timer) { clearTimeout(timer) } timer = setTimeout(function () { timer = null; fn.apply(that, args) }, wait) } } // 节流 export function throttle(fn, wait = 3000) { let timer = null; return function () { if (timer != null) return; let args = arguments; let that = this; clearTimeout(timer) fn.apply(that, args) timer = setTimeout(function () { timer = null; }, wait) } }