debounce(fn, wait)Implement a debounce utility function.
Given a function fn and a delay wait (milliseconds), debounce(fn, wait) returns a new function debounced such that:
debounced(...args)
is called repeatedly, it postpones calling
fn
until
after
wait
ms have elapsed since the
most recent
call.
fn
is invoked
once
with the
latest
arguments and the original
this
context.
this
binding when invoking
fn
.
debounced.cancel()
to cancel a pending invocation.
debounced.flush()
to immediately run the pending invocation (if any).