Guest User

Untitled

a guest
Mar 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function throttle(fn, delay, context) {
  2. var timer;
  3. var context = context || this;
  4. var first = true;
  5. return function() {
  6. if (first) {
  7. fn.apply(context, [].slice.apply(arguments));
  8. first = false;
  9. }
  10. if (timer) {
  11. return;
  12. }
  13. timer = setTimeout(function() {
  14. clearTimeout(timer);
  15. timer = null;
  16. fn.apply(context, [].slice.apply(arguments));
  17. }, delay);
  18. }
  19. }
  20.  
  21. function debounce(fn, delay, context) {
  22. var timer;
  23. var context = context ||this;
  24. return function() {
  25. clearTimeout(timer);
  26. timer = setTimeout(fn || function() {
  27. fn.apply(context, [].slice(arguments));
  28. }, delay);
  29. }
  30. }
Add Comment
Please, Sign In to add comment