Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const debounce = (func, wait, immediate) => {
- try {
- let timeout;
- return function() {
- const context = this;
- const args = arguments;
- const later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- const callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- } catch (e) {
- console.log(e);
- }
- };
- const throttled = (delay, fn) => {
- let lastCall = 0;
- return (...args) => {
- const now = new Date().getTime();
- if (now - lastCall < delay) {
- return;
- }
- lastCall = now;
- return fn(...args);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement