Advertisement
Guest User

Untitled

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