> Sorry to be dense, but I still don't get it. How can an object have duplicate > properties? I understand that own properties override properties on > prototypes.
When you look at the object literal var source = { foo: 123 }; then you have e.g. "toString" in source === true "hasOwnProperty" in source === true When doing var target = {}; Object.extend(target, source) then target gets all those properties *again* (in addition to inheriting them from Object.prototype). target.hasOwnProperty(toString) === true Object.getPrototypeOf(target).hasOwnProperty === true The following illustrates duplicate properties: var proto = { foo: 123 }; var obj = Object.create(proto); console.log(obj.foo === 123); // true obj.foo = 345; console.log(proto.foo === 123); // true Thus, the property "foo" exists twice. > I don’t see a simple way of “fixing” (property descriptors do have their > uses) Object.create(). > > Just allow the second argument to be property descriptor *or* object. Problem: property descriptors are indistinguishable from normal objects, they *are* normal objects. > But, in a way, the proto operator <| is that fix. > > Well as far as I can make out from > http://wiki.ecmascript.org/doku.php?id=harmony:proto_operator that operator > is limited to member expressions. Right, my bad, the rhs has to be an object literal. But that still takes are of many (if not most) use cases. -- Dr. Axel Rauschmayer a...@rauschma.de twitter.com/rauschma home: rauschma.de blog: 2ality.com
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss