Michael Theriot (2016-03-18T22:18:48.000Z)
michael.lee.theriot at gmail.com (2016-03-18T23:43:11.586Z)
I think I figured out how to make inheritance work... ```js var wm1 = new WeakMap(); function A() { let proxy = new Proxy(this, { get: (target, property, receiver) => property === 'bacon' || target[property] }); wm1.set(proxy, {}); return proxy; } var wm2 = new WeakMap(); function B() { let proxy = A.call(new Proxy(this, { get: (target, property, receiver) => property === 'ham' || target[property] })); wm2.set(proxy, {}); return proxy; } var a = new A(); var b = new B(); wm1.has(a); // true wm2.has(a); // false wm1.has(b); // true wm2.has(b); // true a.bacon; // true a.ham; // undefined b.bacon; // true b.ham; // true ``` I can't imagine this is good for optimizations though. But I guess it does what I need. Edit: Actually I seem to have it backwards... I believe the correct way would be the following: ```js function B() { let proxy = new Proxy(A.call(this), { get: (target, property, receiver) => property === 'ham' || target[property] }); wm2.set(proxy, {}); return proxy; } ```
michael.lee.theriot at gmail.com (2016-03-18T22:22:46.090Z)
I think I figured out how to make inheritance work... ```js var wm1 = new WeakMap(); function A() { let proxy = new Proxy(this, { get: (target, property, receiver) => property === 'bacon' || target[property] }); wm1.set(proxy, {}); return proxy; } var wm2 = new WeakMap(); function B() { let proxy = A.call(new Proxy(this, { get: (target, property, receiver) => property === 'ham' || target[property] })); wm2.set(proxy, {}); return proxy; } var a = new A(); var b = new B(); wm1.has(a); // true wm2.has(a); // false wm1.has(b); // true wm2.has(b); // true a.bacon; // true a.ham; // undefined b.bacon; // true b.ham; // true ``` I can't imagine this is good for optimizations though. But I guess it does what I need.