var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
// Usage:
$('input').keyup(function() {
delay(function(){
alert('Time elapsed!');
}, 1000 );
});