Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. const debounce = (func, wait, immediate) => {
  2. var timeout;
  3. return function () {
  4. var context = this, args = arguments;
  5. var later = function () {
  6. timeout = null;
  7. if (!immediate)
  8. return func.apply(context, args);
  9. };
  10. var callNow = immediate && !timeout;
  11. clearTimeout(timeout);
  12. timeout = setTimeout(later, wait);
  13. if (callNow)
  14. return func.apply(context, args);
  15. };
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement