SOURCE

function throttle(fn,interval){
    let lastTime;
    return function throttled(){
        const timeSinceLastExeution = Date.now()-lastTime;
        if(!lastTime || timeSinceLastExeution >= interval){
            fn.apply(this,arguments)
            lastTime = Date.now()
        }
    }
}

function process(){
    console.log('DevPoint')
}

const throttledProcess = throttle(process,300) // 节流
// const throttledProcess = debounce(process,500,true) //防抖


let num = 0 
let time =  setInterval(()=>{
    num++
    throttledProcess()
    if(num >= 10){
        clearTimeout(time)
    }
},100)
   

function debounce(func,wait,immediate){
    let timeout
    return function (){
        let context = this;
        let args = arguments
        
        if(timeout) clearTimeout(timeout)
        if(immediate){
            let callNow = !timeout;
            timeout = setTimeout(function(){
                timeout = null
            },wait)
            if(callNow) func.apply(context,args)
        }else{
            timeout = setTimeout(function(){
                func.apply(context,args)
            },wait)
        }
    }
}
console 命令行工具 X clear

                    
>
console