JS手写系列 - 防抖Debounce

47 阅读1分钟
    function debounce (func, wait) {
        let timeout;
        return function () {
            let context = this;
            let args = arguments;
            if(timeout) clearTimeout(timeout);
            timeout = setTimeout(function(){
                func.apply(context, args);
            }, wait);
        }
    }
`