On Tue, Sep 7, 2010 at 9:57 PM, Sam Tobin-Hochstadt <sa...@ccs.neu.edu>wrote:
> > Hi Sam, glad to see this coming together. A couple questions: > > 1) Given > > const n = new Name(); > > const x = Object.freeze({...}); > > what does > > x[n] = 88; > > do? > > Produces an error, just as x["n"] would. > This means that Names cannot be used as virtual "expando" properties on frozen objects. > 2) Given > > const n = new Name(); > > const x = Proxy.create(..., ...); > > what does > > x[n] = 88; > > do? > > Calls the 'set' trap of 'x' with x, n, and 88 as arguments. > I would then guess that using it as an rvalue, "x[n]", would invoke the 'get' trap of x's handler with x and n as arguments. So if x is an object of unknown provenance, n may be captured by that object and used to look up field values on other objects that should have been hidden from x. Syntax aside, these are both semantic differences with ExplicitSoftFields. In the corresponding examples: 1) const f = ExplicitSoftField(); const x = Object.freeze({...}); f.set(x, 88); works, rather than throwing an error, because the state being mutated is in f rather than x. Unlike Names, this means that ExplicitSoftFields can be used as generic collision-free "expando" properties, even on frozen objects. 2) const f = ExplicitSoftField(); const x = Proxy.create(..., ...); f.set(x, 88); never invokes x's handler, never giving x a chance to steal f, since only x's identity is used by f to look up or store associations. Identity tests on a proxy, by design, do not trap to the handler. -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss