Documentación offline JavaScript main

FinalizationRegistry() constructor

main Documentación oficial Licencia CC-BY-SA-2.5Descargado el 2026-08-02

En esta página

The FinalizationRegistry() constructor creates {{jsxref("FinalizationRegistry")}} objects.

Syntax#

new FinalizationRegistry(callbackFn)

[!NOTE] FinalizationRegistry() can only be constructed with new. Attempting to call it without new throws a {{jsxref("TypeError")}}.

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 {{jsxref("FinalizationRegistry/register", "register()")}} method when the target object was registered.

Examples#

Creating a new registry#

You create the registry passing in the callback:

const registry = new FinalizationRegistry((heldValue) => {
  // …
});

Specifications#

{{Specifications}}

Browser compatibility#

{{Compat}}

See also#

  • {{jsxref("FinalizationRegistry")}}