Skip to content

Commit 3b947bd

Browse files
committed
Throttle: Only clear timeouts if they exist
Not sure if this is a real performance issue, but every call to clearTimeout is shown in Chrome Timeline.
1 parent 22650b6 commit 3b947bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

underscore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@
744744
context = this;
745745
args = arguments;
746746
if (remaining <= 0 || remaining > wait) {
747-
clearTimeout(timeout);
748-
timeout = null;
747+
if(timeout) {
748+
clearTimeout(timeout);
749+
timeout = null;
750+
}
749751
previous = now;
750752
result = func.apply(context, args);
751753
if (!timeout) context = args = null;

0 commit comments

Comments
 (0)