编辑代码

function debounce(fn,wait){
    let timer = 0;
    return function(...args){
        let now = new Date()
        if(now - timer>wait){
            fn(...args)
            timer = now
        }
    }
}

let conso = function (){
    console.log(111)
}

let debouncefn = debounce(conso,2000)

window.addEventListener("click",debouncefn)

function debounce(fn,wait){
    let timer = null;
    return function(...args){
        if(timer){
            clearTimeout(timer)
        }
        timer =  setTimeout(()=>{
            fn(...args)
        },wait)
    }
}