Re: Object.extends (was Re: traits feedback)

2011-10-09 Thread Axel Rauschmayer
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. Such a method would be very useful independently of this use case! I would also love to have turn Object.defineProperties

Re: Object.extends (was Re: traits feedback)

2011-10-08 Thread Brendan Eich
On Oct 7, 2011, at 11:39 AM, John J Barton wrote: On Fri, Oct 7, 2011 at 11:08 AM, Axel Rauschmayer a...@rauschma.de 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*

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John-David Dalton
On Fri, Oct 7, 2011 at 10:17 AM, Jake Verbaten rayn...@gmail.com wrote: Object.extend is the only method I shim on every es5 project, so +1 However arguments like library X is would break are stupid, remember es6 is an opt-in so backwards compat with existing code be damned. No U! My concern

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Quildreen Motta
2011/10/7 John-David Dalton john.david.dal...@gmail.com As for the functionality, it should just be an n-ary function which extends the first object with all the _own_ properties of the other n-1 objects. If keys clash give right precedence. I've used this flavor of extends too (minus

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
Several people advocate Object.extend() that copies only own properties. I don't understand why; I'll make the case for copying all properties. At a call site I use, say foo.bar(); Ordinarily I should not be concerned about details of bar()'s implementation. In particular I should not be

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Axel Rauschmayer
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

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
On Fri, Oct 7, 2011 at 9:23 AM, Axel Rauschmayer a...@rauschma.de 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

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Axel Rauschmayer
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

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
On Fri, Oct 7, 2011 at 9:16 AM, Quildreen Motta quildr...@gmail.com wrote: 2011/10/7 John J Barton johnjbar...@johnjbarton.com On Fri, Oct 7, 2011 at 8:34 AM, Axel Rauschmayer a...@rauschma.dewrote: If you do something like var fuz = Object.extend(foo, {paper:'in', shoes:'my'});

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Axel Rauschmayer
Again I'll ask you to consider that fuz.bar() should work. That is what extend means. How can we solve this? It’s possible that you are actually looking for mixins: http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/ One possible solution is to do 2 extends:

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Quildreen Motta
2011/10/7 John J Barton johnjbar...@johnjbarton.com On Fri, Oct 7, 2011 at 9:16 AM, Quildreen Motta quildr...@gmail.comwrote: 2011/10/7 John J Barton johnjbar...@johnjbarton.com On Fri, Oct 7, 2011 at 8:34 AM, Axel Rauschmayer a...@rauschma.dewrote: If you do something like var

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
On Fri, Oct 7, 2011 at 10:04 AM, Axel Rauschmayer a...@rauschma.de 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 = {

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Axel Rauschmayer
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

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Allen Wirfs-Brock
(I'm starting a little late on a long thread so sorry if I repeat things that have already been said. On Oct 7, 2011, at 1:50 AM, John-David Dalton wrote: On Fri, Oct 7, 2011 at 10:17 AM, Jake Verbaten rayn...@gmail.com wrote: Object.extend is the only method I shim on every es5 project, so

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
On Fri, Oct 7, 2011 at 11:08 AM, Axel Rauschmayer a...@rauschma.de 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

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Allen Wirfs-Brock
On Oct 7, 2011, at 9:13 AM, Juan Ignacio Dopazo wrote: On Fri, Oct 7, 2011 at 12:34 PM, Axel Rauschmayer a...@rauschma.de wrote: I would prefer the name Object.copyOwnPropertiesTo(source, target) or Object.copyOwnTo(source, target) to the name “extend” (which, to me, suggests

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread Allen Wirfs-Brock
On Oct 7, 2011, at 9:23 AM, Axel Rauschmayer wrote: ... I would prefer the name Object.copyOwnPropertiesTo(source, target) or Object.copyOwnTo(source, target) to the name “extend” (which, to me, suggests inheritance). I isn't clear from the attribution who said the following. It

Re: Object.extends (was Re: traits feedback)

2011-10-07 Thread John J Barton
On Fri, Oct 7, 2011 at 12:13 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: On Oct 7, 2011, at 9:23 AM, Axel Rauschmayer wrote: ... I would prefer the name Object.copyOwnPropertiesTo(source, target) or Object.copyOwnTo(source, target) to the name “extend” (which, to me, suggests

Object.extends (was Re: traits feedback)

2011-10-06 Thread John J Barton
On Thu, Oct 6, 2011 at 8:04 PM, Andrew Dupont mozi...@andrewdupont.netwrote: (Keep in mind that the 80% use-case for this sort of thing is merging default options with user-supplied options, at least in the code I write. That's a simple case that usually involves merging two plain objects

Re: Object.extends (was Re: traits feedback)

2011-10-06 Thread John-David Dalton
From: Andrew Dupont mozi...@andrewdupont.net JJB has it mostly right. When Sam wrote Object.extend (which was originally Object.prototype.extend), it didn't use hasOwnProperty; my guess is that Sam didn't know about it, because most of us were JavaScript amateurs back in the day, including