UNPKG

@fto-consult/node-utils

Version:

Bibliothèque d'outils pour application nodeJS

19 lines (14 loc) • 476 B
module.exports = function debounce(func, wait, immediate) { var timeout; return function executedFunction(...args) { var context = this; 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); }; };