利用了浏览器onresize的时候,不停的触发done返回的function,返回的funtion的scope(作用域)中copy了父函数done的scope,所以共享done中的变量。

function done(fn, delay_time){
        var start_time = null;
        return function(){
            var curr_time = +new Date();
            !start_time && (start_time = curr_time);
            if (curr_time- start_time >= delay_time){
                fn.apply(this, arguments);
                start_time = curr_time;
            }
        }
    }

window.onresize = done(function(){

      //To Do


        },1000)

 

//http://www.alloyteam.com/2012/11/javascript-throttle/

posted on 2013-08-06 18:07  murongzi  阅读(392)  评论(0编辑  收藏  举报