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
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*
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
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
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
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
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
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
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'});
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:
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
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 = {
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
(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
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
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
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
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
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
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
20 matches
Mail list logo