UNPKG

rax-scrollview

Version:
21 lines 470 B
export default function throttle(func, wait) { var ctx; var args; var rtn; var timeoutID; var last = 0; function call() { timeoutID = 0; last = +new Date(); rtn = func.apply(ctx, args); ctx = null; args = null; } return function () { ctx = this; args = arguments; var delta = new Date().getTime() - last; if (!timeoutID) if (delta >= wait) call();else timeoutID = setTimeout(call, wait - delta); return rtn; }; }