JavaScript专题之跟着 underscore 学节流

https://github.com/mqyqingfeng/Blog/issues/26

function throttle(func, wait) {
    var timeout;
    var previous = 0;

    return function() {
        var context = this;
        var args = arguments;
        if (!timeout) {
            timeout = setTimeout(function(){
                timeout = null;
                func.apply(context, args)
            }, wait)
        }
    }
}

你可能感兴趣的:(JavaScript专题之跟着 underscore 学节流)