Ok, so I do search like in google, you type text in input and it gives you entries instantly. But I don\'t like that. I use something like that $(\"TEXTINPUT\").keyup(
This function will act somewhat like underscore.js, but without the extra dependency. It'll also pass the scope and arguments it's called with to the wrapped function. Unlike YoannM's answer, this returns a self-contained callback that uses no external variables (EG, use as many times as you want).
function throttle (func, wait) {
return function() {
var that = this,
args = [].slice(arguments);
clearTimeout(func._throttleTimeout);
func._throttleTimeout = setTimeout(function() {
func.apply(that, args);
}, wait);
};
}
And usage would be nearly identical to that of the underscore.js library.
$('input').on('input keyup', throttle(function() {
// ...
}, 100));