JS手写系列 - 节流

50 阅读1分钟
    function throttle (func, wait) {
        let timeout;
        return function () {
            let context = this;
            let args = arguments;
            if(!timeout) {
                timeout = setTimeout(function () {
                  timeout = null;
                  func.apply(context, args);
                }, wait);
            }
        }
    }