js节流和防抖

节流:

  1. 

var throttle = function(fn,delay){
         var pre = Date.now();
          return function(){
                var __me = this;
                var args = arguments;
                var now = Date.now();
               if(now - pre >= delay){
                 fn.apply(__me,args);
                 pre = Date.now();
               }
         }
}
var count = 0;
window.onresize = throttle(function(){
         console.log(count++)
},1000)

原文地址:https://www.cnblogs.com/qiyc/p/11295110.html