ghostcode
1/3/2016 - 7:59 AM

节流函数对高频操作限制调用次数,以此提高性能

节流函数对高频操作限制调用次数,以此提高性能

function throttle(method,context){
    clearTimeout(method.flag);
    method.flag = setTimeout(function(){
        method.call(context);
    },100);
}
var throttle = {
    switch:false,
    timer:100,
    process:function(method,context){
        var self = this;
        if(self.switch){
            return;
        }
        self.switch = true;
        setTimeout(function(){
            self.switch = false;
            method.call(context);
        },self.timer);
    }
}