SOURCE

console 命令行工具 X clear

                    
>
console
/**
 * 
 * 防抖函数
 */
function Debance(cb, delay = 500) {
    let timeId = null
    return function(...args) {
        if(timeId) {
            clearTimeout(cb)
        }else {
            timeId = setTimeout(() => {
                cb.call(this,...args)
            },delay)
        }
    }
}

/**
 * 节流函数
 */
function Throttle(cb, delay = 500) {
    let flag = false
    return function(...args) {
        if(!flag) return
        setTimeout(() => {
            cb.call(this, ...args)
            flag = true
        }, delay)
        flag = false
    }
}


const oInput = document.querySelector('input')
    
oInput.addEventListener('input', Throttle(function() {
    console.log('xxxxx')
}, 2000))
<input />