DisposableStack() constructor

The DisposableStack() constructor creates DisposableStack objects.

Syntax

js
new DisposableStack()

Note: DisposableStack() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

None.

Return value

A new DisposableStack object.

Examples

Creating an DisposableStack

js
const disposer = new DisposableStack();
disposer.defer(() => console.log("Disposed!"));
disposer.dispose();
// Logs: Disposed!

Specifications

Specification
ECMAScript Async Explicit Resource Management
# sec-disposablestack-constructor

Browser compatibility

See also