FinalizationRegistry() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The FinalizationRegistry()
constructor creates FinalizationRegistry
objects.
Syntax
Parameters
callback
-
A function to be invoked each time a registered target value is garbage collected. Its return value is ignored. The function is called with the following arguments:
heldValue
-
The value that was passed to the second parameter of the
register()
method when thetarget
object was registered.
Examples
Creating a new registry
You create the registry passing in the callback:
js
const registry = new FinalizationRegistry((heldValue) => {
// …
});
Specifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-finalization-registry-constructor |
Browser compatibility
BCD tables only load in the browser