Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. /**
  2. / Typescript function to throttle frequently occurring events (resize, keydown etc...).
  3. / Example: document.getElementById("inputBox").addEventListener("keyup", throttle(eventHandler, 300));
  4. */
  5.  
  6. function throttle(callback: () => void, limit: number) {
  7. var wait = false;
  8. return () => {
  9. if (!wait) {
  10. callback();
  11. wait = true;
  12. setTimeout(() => {
  13. wait = false;
  14. }, limit);
  15. }
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement