JavaScript FinalizationRegistry Methods

About This Index
This page is the JavaScript FinalizationRegistry Methods index. A FinalizationRegistry has two methods. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what a FinalizationRegistry is on /js/finalization-registry. Use this page when you need a specific method such as register().
First create one with new FinalizationRegistry(callback). Then call registry.register() to start watching an object and registry.unregister() to stop.
How to Call a FinalizationRegistry Method
Create a registry, then call the methods on it:
const registry = new FinalizationRegistry((heldValue) => {
console.log("Cleaned up: " + heldValue);
});
const item = { name: "report" };
const token = {};
registry.register(item, "report", token); // start watching
console.log(registry.unregister(token)); // true (stop watching)
console.log(registry.unregister(token)); // false (already removed) JavaScript FinalizationRegistry Methods Table
All method guides in this JavaScript tutorial series (2 tutorials), grouped by what they do.
Start watching an object
1 methodTell the registry which object to watch and what to remember about it.
| Method | Description | Tutorial |
|---|---|---|
register() | Watch an object, choose the held value for the callback, and add an optional unregister token. | Open |
Stop watching
1 methodCancel registrations you no longer need.
| Method | Description | Tutorial |
|---|---|---|
unregister() | Remove every registration made with a token. Returns true if something was removed, false if not. | Open |
Frequently Asked Questions
Start with register()
Open the guide for watching an object with a registry: syntax, examples, and FAQs.
9 people found this page helpful
