Interface: Disposable

Disposable

Represents an object that should be initialized prior to use, and disposed when no longer needed. Both functions are optional. Most useful for user-defined objects that make use of, and/or maintain references to, host objects, but any object can implement this interface.

As both Disposable#init and Disposable#dispose are optional, usage of a Disposable (absent knowledge of their implementation on a specific target type) should be akin to the following:

if (typeof disposable.init === 'function') {
    disposable.init()
}

// Usage of the Disposable object...

// Disposable no longer needed
if (typeof disposable.dispose === 'function') {
    disposable.dispose();
}

Methods

dispose()

Optional function to dispose this object. The object should not be relied upon to be usable after calling this function, however whether it actually is, or not, is entirely implementation-dependent.

Source:

init()

Optional function to initialize this object for use. The object should be usable after calling this function.

Source: