Actual WeakSet Use Cases

Domenic Denicola d at domenic.me
Tue Jun 2 15:14:20 UTC 2015


WeakSets are perfect for branding and are how I would expect web platform class branding to be explained.

```js
const foos = new WeakSet();

class Foo {
  constructor() {
    foos.add(this);
  }
  
  method() {
    if (!foos.has(this)) {
      throw new TypeError("Foo.prototype.method called on an incompatible object!");
    }
  }
}
```



More information about the es-discuss mailing list