Not resolving this like o3 (or o6 really) sounds very strange. I think: let attr = "__proto__"; let o7 = new Object; o7[attr] = p; // o7 inherits from p
Is the correct behavior here (why would it not invoke the setter?) On Wed, Oct 16, 2013 at 12:04 AM, Dean Landolt <[email protected]> wrote: > > > > On Mon, Oct 14, 2013 at 8:32 PM, Allen Wirfs-Brock > <[email protected]>wrote: > >> >> On Oct 14, 2013, at 4:21 PM, Andrea Giammarchi wrote: >> >> > my last memories on the topic are these: >> > >> > ```javascript >> > >> > var obj = JSON.parse('{"__proto__":[]}'); >> > obj instanceof Array; // false >> > obj.__proto__ instanceof Array; // true >> > // since the proto is a property, not a magic thing >> > obj.__proto__ = 123; // da hell will happen, only Allen knows ^_^ >> > >> > ``` >> > >> > And since latter should simply set the property named `"__proto__"` as >> value `123` I got confused with this dual way to deal with an object when >> it comes from JSON world (then has a property defined as value, not the >> inherited set/get from Object.prototype) >> > >> > As summary, `JSON.parse` over `"__proto__"` is similar to: >> > ```javascript >> > >> > var o = {}; >> > Object.defineProperty(o, '__proto__', { >> > value: 123, >> > enumerable: true, >> > writable: true, >> > configurable: true >> > }); >> > >> > ``` >> > >> > Which means in such case the property `"__proto__"` will fail with such >> object while `Object.setPrototypeOf` won't which is the reason I keep >> suggesting the latest to make the intent explicit. >> > >> > Not arguing or anything, just speaking out loudly my confusion with >> that property as string part. >> > >> >> I think you are over thinking this: >> >> Assuming that Annex B.2.2.1 and B.3.1 are implemented: here are the cases >> of interest: >> >> let o1 = {__proto__: p}; // o1 inherits from p >> let o2 = {"__proto__": p}; // o2 inherits from p >> let o3 = {["__proto__"]: p};// o3 inherits from Object.prototype, has own >> data property "__proto__" whose value is p. >> let o4 = JSON.parse('{"__proto__": "value"}'); >> //o4 inherits from Object.prototype, has own data property >> "__proto__" whose value is "value" >> >> //assuming that Object.prototype.__proto__ has not been tamper with: >> let o5 = new Object; >> o5.__proto__ = p ; //o5 inherits from p >> >> let o6 =new Object; >> o6["__proto__"] = p; //o6 inherits from p >> > > There seems to be an interesting case missing: > > let attr = "__proto__"; > let o7 = new Object; > o7[attr] = p; // is this like o3? > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

