参看这一篇博客:《函数防抖与函数节流》
还有司徒正美老师给我们的图示参考:http://demo.nimius.net/debounce_throttle/
非常好的参考文章,根据他的思路,我写了一个不考虑 this 和传参的简介版代码
防抖函数
const debounce = (fn,delay)=>{let timeoutreturn ()=>{if(timeout){clearTimeout(timeout)}timeout = setTimeout(fn,delay)}}
节流函数
const throttle = (fn,threshold)=>{let currentDatereturn ()=>{let newDate = new Dateif(currentDate && newDate - currentDate < threshold) {return}currentDate = newDatefn()}}
「@浪里淘沙的小法师」
