The FinalizationRegistry() constructor creates FinalizationRegistry objects.
Syntax
new FinalizationRegistry(callbackFn)
[!NOTE]
FinalizationRegistry()can only be constructed withnew. Attempting to call it withoutnewthrows a 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 FinalizationRegistry/register method when the
targetobject was registered.
- : The value that was passed to the second parameter of the FinalizationRegistry/register method when the
- : 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:
Examples
Creating a new registry
You create the registry passing in the callback:
const registry = new FinalizationRegistry((heldValue) => {
// …
});
Specifications
Browser compatibility
See also
- FinalizationRegistry
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
