Skip to content

Instantly share code, notes, and snippets.

@powerbot15
Last active December 28, 2015 04:18
Show Gist options
  • Save powerbot15/7440871 to your computer and use it in GitHub Desktop.
Save powerbot15/7440871 to your computer and use it in GitHub Desktop.
lesson6 homework
;(function(){
var limited = function(delay,functionToFreeze){
if(typeof delay === 'function'){
functionToFreeze = delay;
delay = 20;
}
var notExecutingNow=true,
savedArguments,
self,
defaultInputValueLength=0;
return function(){
savedArguments = arguments;
self = this;
if(notExecutingNow){
notExecutingNow = false;
window.setTimeout(function(){
functionToFreeze.apply(self,savedArguments);
notExecutingNow = true;
},delay);
}
}
};
document.getElementById('input').addEventListener('keyup', limited(500, function(){
console.log(input.value);
}));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment