FinalizationRegistry() constructor
En esta página
The FinalizationRegistry() constructor creates {{jsxref("FinalizationRegistry")}} objects.
Syntax#
new FinalizationRegistry(callbackFn)
[!NOTE]
FinalizationRegistry()can only be constructed withnew. Attempting to call it withoutnewthrows 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
targetobject 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")}}