Debounce

Debounces a function so it won't be executed until after a given delay has passed since the most recent time it was called.

Debounce

debounce(fn, delay)

Creates a new version of the function fn, which will only be executed once delay milliseconds has passed since the most recent time it was called.

Arguments

fn

A function to be debounced.

delay

The number of milliseconds that must pass since the most recent time the function is called before it will be executed.

Examples

This button will only be activated after 200 ms has passed since its last activation:

This button will only be activated after a second has passed since its last activation: