Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 309 Bytes

File metadata and controls

18 lines (14 loc) · 309 Bytes

Exercise

Implement debounce

Solution

function debounce(fn, time, context = this) {
    let timeout;
    let callbackArgs;

    return function() {
       callbackArgs = arguments;
       clearTimeout(timeout);
       timeout = setTimeout(fn.bind(context, ...callbackArgs),time);
    }
}