functionthrottle(fn, delay) { var last, deferTimer returnfunction(args) { var self = this var now = +newDate() if (last && now < last + delay) { clearTimeout(deferTimer) deferTimer = setTimeout(function() { last = now fn.call(self, args) }, delay) } else { last = now fn.call(self, args) } } }
var throttleAjax = throttle(ajax, 1000)
var inputc = document.getElementById('throttle') inputc.addEventListener('keyup', function(e) { throttleAjax(e.target.value) })