Skip to content

Commit 334e278

Browse files
committed
Optimise default types
1 parent 093873b commit 334e278

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/throttle.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
//
99
// Returns: <Function>
1010
const throttle = (timeout, fn, ...args) => {
11-
let timer;
11+
let timer = null;
1212
let wait = false;
1313

1414
const execute = args
1515
? (...pars) => (pars ? fn(...args, ...pars) : 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)