Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Usage:
- * delayedExec(function(value) {console.log(value);}, 500, val);
- * @param {Function} fn [description]
- * @param {[type]} delay [description]
- * @return {[type]} [description]
- */
- function delayedExec(fn, delay) {
- var args = Array.prototype.slice.call(arguments).slice(2);
- clear(fn);
- delayedExec[fn] = setTimeout(function() {
- fn.apply(null, args);
- clear(fn);
- }, delay, args);
- function clear(fn) {
- if(delayedExec[fn]) clearTimeout(delayedExec[fn]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement