Event filter

A group of functions that filter the execution of event handlers. These are bundled with batonjs.

debounce

It delays the execution of a function for a specified time, and if the function is called again during the wait, it delays the execution further starting from that point. As a result, only the last call in a sequence of function calls will be executed.

Debounce can be useful in improving program performance when processing resize events, mouse move events, and so on. These events occur in sequence, but not all of them need to be processed, and in many cases it is sufficient to process only the last one.

element.addEventListener("resize", debounce(myEventHandler, 300))
Parameters
name type default description
fn function mandatory Original function. An original function is a function that takes any number of arguments and does not return a value.
delay number mandatory Specify the time in milliseconds (1/1000 of a second) to delay the execution of the function.
Return Value
name type description
fn function Function to which the filter is applied

throttle

Adjusts the execution of the function so that it occurs at most once within the specified interval.

throttle may help improve program performance in handling scrolling events etc. This is because these events occur in rapid succession, but processing all of them may slow down program execution too much.

element.addEventListener("scroll", throttle(myEventHandler, 300))
Parameters
name type default description
fn function mandatory Original function. An original function is a function that takes any number of arguments and does not return a value.
interval number mandatory Specify the function execution interval in milliseconds (1/1000th of a second).
Return Value
name type description
fn function Function to which the filter is applied