Question about proxies and non-class inheritance with private fields

email at email at
Sun Aug 27 16:18:20 UTC 2017

Given "Private fields are designed to have semantics analogous to 
( and 
"All ECMAScript objects, including Proxies, and any user exotic object, 
should have a [[PrivateFieldValues]] internal slot iniitlaized to an 
empty List." 
(, does 
this mean the implementation of private fields will break uses of 
Object.create and Proxy usage as user-defined WeakMap implementations do 

For example:

const priv = new WeakMap()

class Foo {
   constructor () {
     priv.set(this, 'data')
   logChar () {

new Foo().logChar() //-> 'd'
Object.create(new Foo()).logChar() // Err: no charAt in undefined
new Proxy(new Foo(), {}).logChar() // Err: no charAt in undefined

The problem being that `this` in `logChar` for the created object and 
proxy are different instances than the `this` associated with the 
private map's 'data'.  So the "private slots" of those instances do not 
match the objects they wrap, instead being empty/uninitialized.

I figured proxies would at least need to be able to handle situations 
like this. An example on MDN shows a proxy using methods like 
`setItem()` and `getItem()` from its target which, if implemented with 
private data, would could cause failures like the one seen above 
I've seen mention of the "proxy problem" in various places with respect 
to private fields but wasn't sure if there was a solution in place for 
it - or even if it necessarily referred to what I'm describing here.  
But the observations above suggests that using proxies may not be safe - 
at least not without familiarity with the implementation of the object 
you're proxying. So I just want to make sure I understand it correctly.


More information about the es-discuss mailing list