fn.js

Methods

static bind(context, fn, uidopt) → {function}

[utils/fn.js](https://docs.videojs.com/utils_fn.js.html), [line 30](https://docs.videojs.com/utils_fn.js.html#line30)

Bind (a.k.a proxy or context). A simple method for changing the context of a function.

It also stores a unique id on the function so it can be easily removed from events.

Parameters:
NameTypeAttributesDescription
contextMixed

The object to bind as scope.

fnfunction

The function to be bound to a scope.

uidnumber<optional>

An optional unique ID for the function to be set

Returns:

function -

The new function that will be bound into the context given

static debounce(func, wait, immediateopt, contextopt) → {function}

[utils/fn.js](https://docs.videojs.com/utils_fn.js.html), [line 104](https://docs.videojs.com/utils_fn.js.html#line104)

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

Inspired by lodash and underscore implementations.

Parameters:
NameTypeAttributesDefaultDescription
funcfunction

The function to wrap with debounce behavior.

waitnumber

The number of milliseconds to wait after the last invocation.

immediateboolean<optional>

Whether or not to invoke the function immediately upon creation.

contextObject<optional>
window

The “context” in which the debounced function should debounce. For example, if this function should be tied to a Video.js player, the player can be passed here. Alternatively, defaults to the global window object.

Returns:

function -

A debounced function.

static throttle(fn, wait) → {function}

[utils/fn.js](https://docs.videojs.com/utils_fn.js.html), [line 63](https://docs.videojs.com/utils_fn.js.html#line63)

Wraps the given function, fn, with a new function that only invokes fn at most once per every wait milliseconds.

Parameters:
NameTypeDescription
fnfunction

The function to be throttled.

waitnumber

The number of milliseconds by which to throttle.

Returns:

function