Fixes #170, #266 ... throttle now starts at the beginning of the call.

This commit is contained in:
Jeremy Ashkenas
2011-10-24 12:05:59 -04:00
parent 456a69c559
commit bceb77e325
2 changed files with 21 additions and 18 deletions

View File

@@ -90,7 +90,7 @@ $(document).ready(function() {
_.delay(function(){ ok(deferred, "deferred the function"); start(); }, 50);
});
asyncTest("functions: throttle", 1, function() {
asyncTest("functions: throttle", 2, function() {
var counter = 0;
var incr = function(){ counter++; };
var throttledIncr = _.throttle(incr, 100);
@@ -99,6 +99,7 @@ $(document).ready(function() {
setTimeout(throttledIncr, 140);
setTimeout(throttledIncr, 220);
setTimeout(throttledIncr, 240);
_.delay(function(){ ok(counter == 1, "incr throttle was called immediately"); }, 40);
_.delay(function(){ ok(counter == 3, "incr was throttled"); start(); }, 400);
});