参看这一篇博客:《函数防抖与函数节流》
    还有司徒正美老师给我们的图示参考:http://demo.nimius.net/debounce_throttle/

    非常好的参考文章,根据他的思路,我写了一个不考虑 this 和传参的简介版代码

    防抖函数

    1. const debounce = (fn,delay)=>{
    2. let timeout
    3. return ()=>{
    4. if(timeout){
    5. clearTimeout(timeout)
    6. }
    7. timeout = setTimeout(fn,delay)
    8. }
    9. }

    节流函数

    1. const throttle = (fn,threshold)=>{
    2. let currentDate
    3. return ()=>{
    4. let newDate = new Date
    5. if(currentDate && newDate - currentDate < threshold) {
    6. return
    7. }
    8. currentDate = newDate
    9. fn()
    10. }
    11. }

    「@浪里淘沙的小法师」