Skip to content

Commit 1fe6562

Browse files
authored
Optimise default types
1 parent 093873b commit 1fe6562

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/throttle.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const throttle = (timeout, fn, ...args) => {
1616
: (...pars) => (pars ? fn(...pars) : fn());
1717

1818
const delayed = (...pars) => {
19-
timer = undefined;
19+
timer = null;
2020
if (wait) execute(...pars);
2121
};
2222

@@ -38,12 +38,15 @@ const throttle = (timeout, fn, ...args) => {
3838
// fn - <Function>, to be debounced
3939
// args - <Array>, arguments for fn, optional
4040
const debounce = (timeout, fn, ...args) => {
41-
let timer;
41+
let timer = null
4242

4343
const debounced = () => (args ? fn(...args) : fn());
4444

4545
const wrapped = () => {
46-
if (timer) clearTimeout(timer);
46+
if (timer) {
47+
clearTimeout(timer);
48+
timer = null;
49+
}
4750
timer = setTimeout(debounced, timeout);
4851
};
4952

0 commit comments

Comments
 (0)