javascript 去抖功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 去抖功能相关的知识,希望对你有一定的参考价值。

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce( func, wait, immediate ) {
  var timeout;
  return function () {
    var context = this,
      args = arguments;
    var later = function () {
      timeout = null;
      if ( !immediate ) func.apply( context, args );
    };
    var callNow = immediate && !timeout;
    clearTimeout( timeout );
    timeout = setTimeout( later, wait );
    if ( callNow ) func.apply( context, args );
  };
};

以上是关于javascript 去抖功能的主要内容,如果未能解决你的问题,请参考以下文章

javascript 功能去抖

理解JavaScript中的去抖函数

javascript 去抖

javascript 去抖

javascript 去抖函数

javascript 去抖