From: Kevin Smith [mailto:[email protected]]
> Also, this proposal doesn't depend upon WeakMaps for private fields, per se.
> We could imagine some new, opaque thing that uses the same
> "referenceGet/Set/Delete" mechanism.
That's a good point. Just to prove it, here's a hypothetical PrivateSymbol
version:
```js
PrivateSymbol.prototype[Symbol.referenceGet] = function (obj) {
return obj[this];
};
PrivateSymbol.prototype[Symbol.referenceSet] = function (obj, value) {
obj[this] = value;
};
PrivateSymbol.prototype[Symbol.referenceDelete] = function (obj) {
delete obj[this];
};
const _x = new PrivateSymbol("x");
// ... inside a class
this::_x = x;
```
Note that this is pretty much exactly the same as a WeakMap in terms of
author-facing ergonomics, but for implementers it gives them a separate
PrivateSymbol type that they can optimize with a use case focused toward
private state and object property access, instead of as an ephemeron table.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss