Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Managing timeout. Especially handy with autocomplete.
// Props to : http://nathanleclaire.com/blog/2013/11/16/the-javascript-question-i-bombed-in-an-interview-with-a-y-combinator-startup/
var processOnTime = function ( next, delay ) {
var d = delay;
if ( ! next ) {
throw new ReferenceError();
}
if ( ! d || isNaN ( d ) ) {
d = 200;
}
if ( this.timeoutID ) window.clearTimeout ( this.timeoutID );
this.timeoutID = setTimeout ( function () {
next();
}, d );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment