Skip to content

Commit 48eff23

Browse files
committed
Refactored utils.func.debounce and utils.func.throttle methods.
1 parent 2e701e2 commit 48eff23

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/utils/FunctionUtil.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@ FunctionUtil = {
4444
{
4545
var timeoutId;
4646
return function() {
47-
var args = arguments;
4847
if (timeoutId) {
4948
clearTimeout(timeoutId);
5049
timeoutId = null;
5150
}
51+
var args = arguments;
5252
timeoutId = setTimeout(function() {
5353
func.apply(scope, args);
5454
}, milliseconds);
5555
};
56+
/*
57+
var timeoutId;
58+
return function() {
59+
if (timeoutId) {
60+
timeoutId.cancel();
61+
timeoutId = null;
62+
}
63+
timeoutId = FunctionUtil.delay.apply(null, [milliseconds, func, scope].concat(arguments));
64+
};
65+
*/
5666
},
5767

5868
delay: function(milliseconds, func, scope)
@@ -107,16 +117,14 @@ FunctionUtil = {
107117
{
108118
var timeoutId;
109119
return function() {
110-
var args = arguments;
111120
if (timeoutId) {
112121
return;
113-
} else {
114-
func.apply(scope, args);
115-
timeoutId = setTimeout(function() {
116-
clearTimeout(timeoutId);
117-
timeoutId = null;
118-
}, milliseconds);
119122
}
123+
func.apply(scope, arguments);
124+
timeoutId = setTimeout(function() {
125+
clearTimeout(timeoutId);
126+
timeoutId = null;
127+
}, milliseconds);
120128
};
121129
},
122130

0 commit comments

Comments
 (0)