JS中的防抖和节流
防抖:多次触发后执行一次
节流:多次触发只在规定时间内执行一次
//防抖 function debounce(func,await){ let timeout return function(){ let content = this let args = arguments if(timeout) clearInterval(timeout) timeout = setTimeout(()=>{ func.apply(content,args) },await) } } //节流 function throttle(func,await){ let previous = 0 return function(){ let now = Date.now() let context = this let args = arguments if(now-previous>await){ func.apply(context,args) previous = now } } }