UNPKG

@antv/util

Version:

> AntV 底层依赖的工具库,不建议在自己业务中使用。

22 lines (20 loc) 488 B
function debounce(func: Function, wait?: number, immediate?: boolean) { let timeout; return function () { const context = this, args = arguments; const later = function () { timeout = null; if (!immediate) { func.apply(context, args); } }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) { func.apply(context, args); } }; } export default debounce;