1 module.exports = throttle;
4 * Returns a new function that, when invoked, invokes `func` at most once per `wait` milliseconds.
6 * @param {Function} func Function to wrap.
7 * @param {Number} wait Number of milliseconds that must elapse between `func` invocations.
8 * @return {Function} A new function that wraps the `func` function passed in.
11 function throttle (func, wait) {
12 var ctx, args, rtn, timeoutID; // caching
15 return function throttled () {
18 var delta = new Date() - last;
20 if (delta >= wait) call();
21 else timeoutID = setTimeout(call, wait - delta);
28 rtn = func.apply(ctx, args);