logo

/Code Snippet|v2.3.2

Module

Static Methods

debounce(fn, delay)debounce.jsline 36

Creates a debounced function that delays invoking fn until after delay milliseconds has elapsed
since the last time the debouced function was invoked.

PARAMETERS
NameTypeDescription

fn

function

The function to debounce.

delay

number = 0

The number of milliseconds to delay

RETURNS:
{

function

} - debounced function.
EXAMPLES
var debounce = require('tui-code-snippet/tricks/debounce'); // node, commonjs

function someMethodToInvokeDebounced() {}

var debounced = debounce(someMethodToInvokeDebounced, 300);

// invoke repeatedly
debounced();
debounced();
debounced();
debounced();
debounced();
debounced();    // last invoke of debounced()

// invoke someMethodToInvokeDebounced() after 300 milliseconds.

throttle(fn, interval)throttle.jsline 38

Creates a throttled function that only invokes fn at most once per every interval milliseconds.
You can use this throttle short time repeatedly invoking functions. (e.g MouseMove, Resize ...)
if you need reuse throttled method. you must remove slugs (e.g. flag variable) related with throttling.

PARAMETERS
NameTypeDescription

fn

function

function to throttle

interval

number = 0

the number of milliseconds to throttle invocations to.

RETURNS:
{

function

} - throttled function
EXAMPLES
var throttle = require('tui-code-snippet/tricks/throttle'); // node, commonjs

function someMethodToInvokeThrottled() {}

var throttled = throttle(someMethodToInvokeThrottled, 300);

// invoke repeatedly
throttled();    // invoke (leading)
throttled();
throttled();    // invoke (near 300 milliseconds)
throttled();
throttled();
throttled();    // invoke (near 600 milliseconds)
// ...
// invoke (trailing)

// if you need reuse throttled method. then invoke reset()
throttled.reset();
Resizable