function throttle (fn, delay) { let last = 0, timer = null return function () { let args = arguments let now = Date.now() if (now - last < delay) { clearTimeout(timer) timer = setTimeout(() => { last = now fn.apply(this, args) }, delay) } else { last = now fn.apply(this, args) } } }