//节流 -- 立即执行回调 function throttle(callback,wait){ let start = 0; return function(e){ let now = Date.now() if(now - start >= wait){ callback.call(this,e) start = now } } } //防抖 -- 事件触发时不会立即触发回调 function debounce(callback,time){ let timer = null return function(e){ if(timer){ clearTimeout(timer) } timer = setTimeout(()=>{ callback.call(this,e) timer = null },time) } }