SOURCE

console 命令行工具 X clear

                    
>
console
// 防抖
let inp = document.getElementById('inp')
inp.addEventListener('input', debounce(search, 500))

function debounce(fn, wait) {
    let timer = null
    return () => {
        clearTimeout(timer)
        timer = setTimeout(function () {
            arr = [1, 2, 5]
            fn.call(this, ...arr)
        }, wait)
    }
}

function search(a, b, c) {
    console.log(a, b, c)
}





// 节流
window.addEventListener('resize', throttle(sayHi, 500))

function sayHi(e) {
    console.log(e.target.innerWidth, e.target.innerHeight);
}

function throttle(fn, wait) {
    let timer = null;
    return function(){
        if (timer) {
            return;
        }
        timer = setTimeout(() => {
            // arguments是对象 可以用apply直接传
            // 使用call需要 ...数组解构
            // fn.apply(this,arguments)
            // console.log(arguments) 
            
            fn.call(this,...arguments)
            timer = null
        }, wait)
    }
}
<input id="inp">