Proposal: Abstract References

Domenic Denicola domenic at
Tue Oct 21 13:37:51 PDT 2014

From: Kevin Smith [mailto:zenparsing at] 

> 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:

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.

More information about the es-discuss mailing list