es-discuss Digest, Vol 56, Issue 57

Quildreen Motta quildreen at
Fri Oct 7 09:16:35 PDT 2011

2011/10/7 John J Barton <johnjbarton at>

> On Fri, Oct 7, 2011 at 8:34 AM, Axel Rauschmayer <axel at> wrote:
>> If you do something like
>>      var fuz = Object.extend(foo, {paper:'in', shoes:'my'});
>> Then fuz will get all properties of Object.prototype, again, as
>> duplicates. In the above, you are clearly most interested in what you see in
>> the literal and those are the own properties.
> I don't understand how you can get properties as duplicates in JS.
> I disagree, since in my example I specifically point out that
> should work.

You can't get duplicate properties, because keys are unique. However, you'll
still get loads of clutter in the target object. Also, again, I'm not sure
the majority of the use-cases would be concerned with copying the properties
in the whole prototype chain -- that's expensive! -- and you could achieve
the latter easily by recursively extending the object.

> And this kind of "extend" enables poor man’s cloning as follows:
>     var orig = { foo: "abc" };
>     var clone = Object.extend(Object.create(Object.getPrototypeOf(orig)),
> orig);
> > Sadly this code will fail since -- surprise! -- Object.create() does not
take an object as the second argument.

Object.create here is only taking a single parameter though. `orig' is being
passed to Object.extend. The kind of problems that arise when you have
overtly verbose qualified names that you can't even keep track of what's

I would prefer the name Object.copyOwnPropertiesTo(source, target) or
> Object.copyOwnTo(source, target) to the name “extend” (which, to me,
> suggests inheritance).

See previous point.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list