Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const debounce = (fn, delay, immediate) => {
- let timeout;
- if (immediate) {
- let locked = false;
- return function(...args) {
- clearTimeout(timeout);
- if (!locked) {
- fn.apply(this, arguments);
- locked = true;
- }
- timeout = setTimeout(() => {
- locked = false;
- }, delay);
- }
- }
- else return function(...args) {
- clearTimeout(timeout);
- timeout = setTimeout(() => {
- fn.apply(this, arguments);
- }, delay);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement