UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ FinalizationRegistry/ FinalizationRegistry.prototype.register()

The register() method of FinalizationRegistry instances registers an value with this FinalizationRegistry so that if the value is garbage-collected, the registry's callback may get called.

Syntax

register(target, heldValue)
register(target, heldValue, unregisterToken)

Parameters

Return value

None (undefined).

Exceptions

Description

See the Avoid where possible and Notes on cleanup callbacks sections of the FinalizationRegistry page for important caveats.

Examples

Using register

The following registers the value referenced by target, passing in the held value "some value" and passing the target itself as the unregistration token:

registry.register(target, "some value", target);

The following registers the value referenced by target, passing in another object as the held value, and not passing in any unregistration token (which means target can't be unregistered):

registry.register(target, { useful: "info about target" });

Specifications

Browser compatibility

See also