Skip to content

Commit c967097

Browse files
committed
fix: Utils.debounce on function with parameters
1 parent 7790800 commit c967097

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils/debounce.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let now = Date.now
33

44
export default function (fn, wait = 250, immediate) {
55
let
6-
timeout, args, context, timestamp, result,
6+
timeout, params, context, timestamp, result,
77
later = () => {
88
let last = now() - timestamp
99

@@ -13,9 +13,9 @@ export default function (fn, wait = 250, immediate) {
1313
else {
1414
timeout = null
1515
if (!immediate) {
16-
result = fn.apply(context, args)
16+
result = fn.apply(context, params)
1717
if (!timeout) {
18-
context = args = null
18+
context = params = null
1919
}
2020
}
2121
}
@@ -26,13 +26,14 @@ export default function (fn, wait = 250, immediate) {
2626

2727
context = this
2828
timestamp = now()
29+
params = args
2930

3031
if (!timeout) {
3132
timeout = setTimeout(later, wait)
3233
}
3334
if (callNow) {
3435
result = fn.apply(context, args)
35-
context = args = null
36+
context = params = null
3637
}
3738

3839
return result

0 commit comments

Comments
 (0)