On Fri, Oct 7, 2011 at 10:04 AM, Axel Rauschmayer <[email protected]> wrote:
> 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.
>
The object |obj| has a property |foo|; the object |proto| has a property
|foo|. The string "foo" appears as property names in two different objects.
I don't understand what problem this will cause for developers. The object
|obj| does not have duplicate properties, it has a unique value for each
property name.
>
> 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.
>
If you pass a normal object to object.Create() you get an error message.
Clearly they can be distinguished.
jjb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss