The FinalizationRegistry() constructor creates FinalizationRegistry objects.
new FinalizationRegistry(callbackFn)Note: FinalizationRegistry() can only be constructed with new. Attempting to call it without new throws a TypeError.
callbackA 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:
heldValueThe value that was passed to the second parameter of the register() method when the target object was registered.
You create the registry passing in the callback:
const registry = new FinalizationRegistry((heldValue) => {
// …
});