函数节流

// (来自)JavaScript高级程序设计 不支持匿名函数
function throttle(fn, context) {
    clearTimeout(fn.tId);
    fn.tId = setTimeout(function () {
        fn.call(context);
    }, 100);
}
// (来自)百度 不支持匿名函数
function throttle(fn) {
    var args, that, timer = null;
    return function () {
        clearTimeout(timer);
        args = arguments;
        that = this;
        timer = setTimeout(function () {
            fn.call(that, args);
        }, 100);
    };
}

 

posted @ 2016-07-05 20:03  koala_熊  Views(99)  Comments(0Edit  收藏  举报