Last active
August 29, 2015 14:03
-
-
Save marksteve/66f376b8db6c4625957c to your computer and use it in GitHub Desktop.
Decorator to limit function calls to every `cd` ms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var throttle = function(f, cd) { | |
var _cd = new Date; | |
return function() { | |
if (_cd - new Date < 0) { | |
_cd = new Date(new Date().getTime() + cd); | |
return f.apply(this, arguments); | |
} | |
}; | |
}; | |
/* | |
var shout = throttle(function() { console.log('SHOUT!'); }, 1000); | |
setInterval(shout, 100); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try
+new Date()
instead of .getTime() :) or evencd + new Date()