Write a function that takes in a callback function and a delay time. The function should return a new function that can only be called once per delay time. If the function is called more than once within the delay time, it should only execute the callback function once, after the delay time has passed.
would return a new function that logs "Hello world!" to the console only once, even if it is called multiple times within the 1000ms delay time.
const debouncedLog = debounceEventLogger(() => console.log('Hello world!'), 1000);
Solution Walkthrough for Basic Debounce
Don't read this unless you've already solved the problem.
function, we are using the
method to call the original
function with the same context and arguments that were passed to the debounced function.
keyword, is determined by the execution context in which the function is called. In the case of the debounced function, the execution context will be the same as the original function that was passed in.
method is used to call the
function with the same context and arguments that were passed to the debounced function. This ensures that the
function is executed with the correct context and arguments, even though it is being called by a different function.