Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // Returns a function, that, as long as it continues to be invoked, will not
  2. // be triggered. The function will be called after it stops being called for
  3. // N milliseconds. If `immediate` is passed, trigger the function on the
  4. // leading edge, instead of the trailing.
  5. function debounce(func, wait, immediate) {
  6. var timeout;
  7. return function() {
  8. var context = this,
  9. args = arguments;
  10. var later = function() {
  11. timeout = null;
  12. if (!immediate) func.apply(context, args);
  13. };
  14. var callNow = immediate && !timeout;
  15. clearTimeout(timeout);
  16. timeout = setTimeout(later, wait);
  17. if (callNow) func.apply(context, args);
  18. };
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement