Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @param {number} delay - milliseconds to delay the call
- * @param {function} fn - the callback to be fired when delay fires
- * @return {function} a function to call multiple times
- */
- module.exports = function debounce(delay, fn) {
- if (typeof delay !== 'number') {
- throw new Error('you must pass in a number');
- }
- if (typeof fn !== 'function') {
- throw new Error('you must pass in a function');
- }
- let timer;
- return function () {
- clearTimeout(timer);
- timer = setTimeout.apply(setTimeout, [fn, delay, ...arguments]);
- };
- };
Add Comment
Please, Sign In to add comment