On Oct 7, 2011, at 11:39 AM, John J Barton wrote:

> On Fri, Oct 7, 2011 at 11:08 AM, Axel Rauschmayer <[email protected]> wrote:
>> 
>>> 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.
> 
> 
> var obj = Object.create(proto, { p: { value: 42 } })
> 
> How would JS distinguish between the property descriptor { value: 42 } and an 
> object whose property "value" has the value 42?
> 
> I would interpret this as a descriptor; if the dev wanted a property they 
> would say {p:42};
> 
> But let's give up on this line, it will never be accepted here.

Or anywhere. The situation is hopelessly ambiguous, or, if you insist on 
classifying all the variations on property descriptor values in an object 
passed as Object.create's second argument as "not normal objects", 
future-hostile. We may want to extend property descriptors in the future. The 
http://traitsjs.org library already does so.


> Let's concentrate on how to create objects given that Object.create(proto) 
> gives an empty object with a prototype of |proto|. Could Object.extend() be 
> defined so devs can combine it with Object.create()? 

Sure, Object.create(proto).extend({k1:v1, ... kN:vN}).

If you want to make that one method instead of two, a new Object.createSimple 
or better name would be needed.

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to