Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. /**
  2. * Usage:
  3. * delayedExec(function(value) {console.log(value);}, 500, val);
  4. * @param {Function} fn [description]
  5. * @param {[type]} delay [description]
  6. * @return {[type]} [description]
  7. */
  8. function delayedExec(fn, delay) {
  9. var args = Array.prototype.slice.call(arguments).slice(2);
  10. clear(fn);
  11. delayedExec[fn] = setTimeout(function() {
  12. fn.apply(null, args);
  13. clear(fn);
  14. }, delay, args);
  15.  
  16. function clear(fn) {
  17. if(delayedExec[fn]) clearTimeout(delayedExec[fn]);
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement