function throttle(fun, delay) { let timer, last return function (args) { const now = new Date.getTime() if (last && now < last + delay) { clearTimeout(timer) timer = setTimeout(() => { last = now fun(args) }, delay) } else { last = now fun.apply(this, args) } } }