bhylu.com

Advertisements

JS Set WeakSet

A WeakSet can track object membership without keeping objects alive solely through that membership. It does not expose an item list.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const checked = new WeakSet();
const card = {title: "Repair club"};
checked.add(card);
console.log(checked.has(card));

What happens

The exact card object is recognised.