Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Use this to cause a function to fire no more than once every 'ms' milliseconds.
- For example, an expensive mousemove handler:
- $('body').mouseover(ratelimit(function(ev) {
- // ...
- }, 250));
- */
- function ratelimit(fn, ms) {
- var last = (new Date()).getTime();
- return (function() {
- var now = (new Date()).getTime();
- if (now - last > ms) {
- last = now;
- fn.apply(null, arguments);
- }
- });
- }
Add Comment
Please, Sign In to add comment