old_contents: /**
   * 添加函数返回值
   */
  
  // 第五版
  function debounce(func, wait, immediate) {
  
      var timeout, result;
  
      return function () {
          var context = this;
          var args = arguments;
  
          if (timeout) clearTimeout(timeout);
          if (immediate) {
              // 如果已经执行过，不再执行
              var callNow = !timeout;
              timeout = setTimeout(function(){
                  timeout = null;
              }, wait)
              if (callNow) result = func.apply(context, args)
          }
          else {
              timeout = setTimeout(function(){
                  func.apply(context, args)
              }, wait);
          }
          return result;
      }
  }
  
  var count = 1;
  var container = document.getElementById('container');
  
  function getUserAction() {
      container.innerHTML = count++;
      return '111'
  };
  
  container.onmousemove = function(){
      var result = debounce(getUserAction, 1000, true)();
      console.log(result)
  }
new_contents: /**
   * 添加函数返回值
   */
  
  // 第五版
  function debounce(func, wait, immediate) {
  
      var timeout, result;
  
      return function () {
          var context = this;
          var args = arguments;
  
          if (timeout) clearTimeout(timeout);
          if (immediate) {
              // 如果已经执行过，不再执行
              var callNow = !timeout;
              timeout = setTimeout(function(){
                  timeout = null;
              }, wait)
              if (callNow) result = func.apply(context, args)
          }
          else {
              timeout = setTimeout(function(){
                  func.apply(context, args)
              }, wait);
          }
          return result;
      }
  }
  
  var count = 1;
  var container = document.getElementById('container');
  
  function getUserAction() {
      container.innerHTML = count++;
      return '111'
  };
  
  var result = debounce(getUserAction, 1000, true)
  container.onmousemove = function(){
      var res = result();
      console.log(res)
  }
subject: 修订 debounce6.js