Are Private name and Weak Map the same feature? and the Assoc API

Tom Van Cutsem at
Mon Dec 19 02:10:34 PST 2011

2011/12/19 Tom Van Cutsem < at>

> In any case, by separating private name access out into separate traps, if
> a proxy writer only implements get/set but not getPrivate/setPrivate, then
> private name access would just be forwarded to the proxy target by default,
> and there would be no need for the proxy to maintain a public->private
> mapping for private names it does not know or care about.

To clarify: the proxy logic I was thinking of is along the following lines:

// in the VM, when intercepting proxy[privateName]:
var trap = handler.getPrivate;
if (typeof trap === "function") {
  return, target, privateName.public); // note: no
ToString on privateName.public
} else {
  return target[privateName]; // note: not target[privateName.public] !!

It's that else-branch that makes this work out: if the proxy doesn't
implement the getPrivate trap, private names will continue to work just
fine. With the .public conversion, any proxy that does not special-case
private names in its get trap will be broken: it'll forward the wrong
property name.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list