#!/JoePea (2019-04-22T18:20:12.000Z)
> 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!");
>     }
>   }
> }
> ```

Just curious, is that effectively the same as what the (current) [private
fields proposal](https://github.com/tc39/proposal-class-fields) offers?

```js
class Foo {
  #isFoo = true

  method() {
    if (this.#isFoo) {
      throw new TypeError("Foo.prototype.method called on an incompatible
object!");
    }
  }
}
```

- Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190422/34d28c4d/attachment.html>
joe at trusktr.io (2019-04-22T18:23:06.066Z)
> 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!");
>     }
>   }
> }
> ```

Just curious, is that effectively the same as what the (current) [private
fields proposal](https://github.com/tc39/proposal-class-fields) offers?

```js
class Foo {
  #isFoo = true

  method() {
    if (this.#isFoo) {
      throw new TypeError("Foo.prototype.method called on an incompatible
object!");
    }
  }
}
```
joe at trusktr.io (2019-04-22T18:23:29.889Z)
> 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!");
>     }
>   }
> }
> ```

Just curious, is that effectively the same as what the (current) [private
fields proposal](https://github.com/tc39/proposal-class-fields) offers?

```js
class Foo {
  #isFoo = true
  
  method() {
    if (this.#isFoo) {
      throw new TypeError("Foo.prototype.method called on an incompatible object!");
    }
  }
}
```