What is the difference between these two implementations in anti-shaking?

Let"s not dwell on the concept of anti-shaking and throttling, but let"s ask what"s the difference between the two. The first is the implementation of underscore

.
 _.now = function (){return new Date().getTime()};
_.debounce = function(func, wait, immediate){
    var timeout, args, context, timestamp, result; 
    var later = function(){
        var last = _.now() - timestamp; 
        if (last < wait && last >= 0) { 
            timeout = setTimeout(later, wait - last); // 
        }else{
            timeout = null;
            result = func.apply(context, args);
            if (!timeout) context = args = null;
        }
    };
    return function(){ 
      context = this; 
      args = arguments; 
      timestamp = _.now(); 
      if (!timeout) 
         timeout = setTimeout(later, wait);
      return result;
    };
};

split

 _.now = function (){return new Date().getTime()};
_.debounce = function(func, wait, immediate){
    var timeout, args, context, timestamp, result; 
    var later = function(){
        timeout = null; // 
        result = func.apply(context, args);
        if (!timeout) context = args = null;
    };
    return function(){ 
      context = this; 
      args = arguments; 
      timestamp = _.now(); 
      if (!timeout) 
         timeout = setTimeout(later, wait);
      return result;
    };
};

what"s the difference between the above two?


I suggest you figure out what throttling is and what is anti-shaking
and this is not recursive

. < hr >

the front one is anti-shaking, and the back one is throttling


I also admire that I can make throttling and anti-shaking so complicated.

function debounce(fn,delay){
    var timer = null; 
    return function(){
      clearTimeout(timer);
      timer = setTimeout(function(){
        fn.apply(this);
      },delay)
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4456b-44a85.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4456b-44a85.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?