Remy Sharp's Function Throttler
trying to use a throttling function created by Remy Sharp (http://remysharp.com/2010/07/21/throttling-function-calls/)... it works in the standard use like so: $('.thing').click(th
Solution 1:
You're doing it wrong ;-)
Here's the solution on jsbin: http://jsbin.com/elabul/edit
The throttle
method returns a function that will throttle the number of times it's called. So you need to capture that bad boy in a variable and call it from inside your click handler, as such:
var inputThrottle = throttle(function () {
console.log('api call');
}, 250);
$('input').keyup(function () {
console.log('test');
inputThrottle();
});
Solution 2:
you need to call returned from throttle function:
$('.thing').click(function() {
console.log('hello!');
(throttle(function() {
console.log('api call');
}, 500))();
});
Solution 3:
Just calling throttle does nothing, you need to return the function as a function to the click handler:
$('.thing').click((function() {
console.log('hello!');
returnthrottle(function() {
console.log('api call');
}, 300);
}()));
Post a Comment for "Remy Sharp's Function Throttler"