From 9fcaac97b6d4d5e243c5fc9eab27979f8f5fbf59 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 24 Oct 2011 14:39:14 -0400 Subject: [PATCH] Removing a redundant finishThrottle check, renaming vars. --- underscore.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/underscore.js b/underscore.js index ab4c26094..60cf2ca8c 100644 --- a/underscore.js +++ b/underscore.js @@ -523,18 +523,18 @@ // Returns a function, that, when invoked, will only be triggered at most once // during a given window of time. _.throttle = function(func, wait) { - var timeout, context, args, throttling, finishThrottle; - finishThrottle = _.debounce(function(){ throttling = false; }, wait); + var context, args, timeout, throttling; + var whenDone = _.debounce(function(){ throttling = false; }, wait); return function() { context = this; args = arguments; - var throttler = function() { + var later = function() { timeout = null; func.apply(context, args); - finishThrottle(); + whenDone(); }; - if (!timeout) timeout = setTimeout(throttler, wait); + if (!timeout) timeout = setTimeout(later, wait); if (!throttling) func.apply(context, args); - if (finishThrottle) finishThrottle(); + whenDone(); throttling = true; }; }; @@ -546,12 +546,12 @@ var timeout; return function() { var context = this, args = arguments; - var throttler = function() { + var later = function() { timeout = null; func.apply(context, args); }; clearTimeout(timeout); - timeout = setTimeout(throttler, wait); + timeout = setTimeout(later, wait); }; };