diff --git a/test/functions.js b/test/functions.js index 3df3e961e..f084b015e 100644 --- a/test/functions.js +++ b/test/functions.js @@ -188,6 +188,7 @@ $(document).ready(function() { equals(testAfter(5, 5), 1, "after(N) should fire after being called N times"); equals(testAfter(5, 4), 0, "after(N) should not fire unless called N times"); + equals(testAfter(0, 0), 1, "after(0) should fire immediately"); }); }); diff --git a/underscore.js b/underscore.js index d27970bbe..7420e87d1 100644 --- a/underscore.js +++ b/underscore.js @@ -595,9 +595,9 @@ // Returns a function that will only be executed after being called N times. _.after = function(times, func) { - return function() { + return times ? function() { if (--times < 1) { return func.apply(this, arguments); } - }; + } : func(); }; // Object Functions