Created
August 25, 2012 17:25
-
-
Save edwinvdgraaf/3468168 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var throttle = function(fn, delay) { | |
delay || (delay = 100); | |
var throttle = false; | |
return function(){ | |
if (throttle){ return; } // you no enter | |
throttle = setTimeout(function(){ | |
// tail it - and do one last ajax request | |
fn.apply(this, arguments); | |
throttle = false; | |
}, delay); | |
fn.apply(this, arguments); | |
}; | |
}; | |
field.on("keyup", throttle(keyUpFn.bind(this), 2000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is beautiful simplicity I needed. Thanks for capturing this solution.