Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. let runing;
  2. let timmer;
  3.  
  4. const throttle = fun => {
  5. if (runing) {
  6. return;
  7. }
  8. runing = true;
  9. setTimeout(() => {
  10. fun();
  11. runing = false;
  12. }, 2000);
  13. };
  14.  
  15. const debounce = fun => {
  16. if (timmer) {
  17. clearTimeout(timmer);
  18. }
  19. timmer = setTimeout(() => {
  20. fun();
  21. }, 2000);
  22. };
  23.  
  24. export { throttle, debounce };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement