diff --git a/test/functions.js b/test/functions.js index f8e5dc5c8..e0de7c2ec 100644 --- a/test/functions.js +++ b/test/functions.js @@ -136,6 +136,16 @@ $(document).ready(function() { _.delay(function(){ equal(counter, 2, "incr was called twice"); start(); }, 220); }); + asyncTest("functions: throttle recursively", 1, function() { + var counter = 0; + var incr = _.throttle(function() { + counter++; + if (counter < 5) incr(); + }, 100); + incr(); + _.delay(function(){ equal(counter, 3, "incr was throttled"); start(); }, 220); + }); + asyncTest("functions: debounce", 1, function() { var counter = 0; var incr = function(){ counter++; }; diff --git a/underscore.js b/underscore.js index 4ca8f6724..d544da9d6 100644 --- a/underscore.js +++ b/underscore.js @@ -541,10 +541,10 @@ if (throttling) { more = true; } else { + throttling = true; result = func.apply(context, args); } whenDone(); - throttling = true; return result; }; };