As far as I can recall, we didn't discuss a specific formulation that 
corresponds to Object.extend but we have considered (and arguably provided) 
pretty much equivalent functionality in our proposal. I assume that at least 
Doug, Adam, or Kris were specifically aware of Object.extend and would have 
broad it up if it was relevant.  One reason, it probably wasn't was that the 
starting point of our design was the full reification and control of properties 
and their attributes rather than just copying properties. By the time we got 
around to cloning/copying issues we already had establish some core elements of 
our overall design.

Doing a bit of search I've found several different variants of the extend 
function.  Some are defined on Object, some on Object.prototype.  Some use a 
single source object and some use multiple source objects.  What they all seem 
to have in common is that they copy the enumerable methods from one (or more) 
object to another.

The most common use case seems to be the one where the target object is a newly 
instantiated object without any properties of its own. That use case (at least 
for variants of extend that only take a single source object) is most directly 
supported by the Object.clone function in our proposal. However, Object.clone 
is defined to be a more comprehensive object duplication process than is 
performed by extend.  It duplicates all own properties and their attributes and 
any internal properties such as its [[Value]] property if it has one.

I have personally considered whether there should be some sort of mechanism to 
filter the properties copied by Object.clone.  For example, you might only copy 
non getter/setter properties, or only enumerable properties, or perhaps filter 
out ReadOnly properties. However, I never proposed any of these for the ES3.1 
spec. because I have yet to find a use case that was sufficiently compelling or 
pervasive enough to justify making the interface to Object.clone more complex 
(in contrast, see the explanation in the rationale document for why we added a 
second argument to Object.create).  If you want to do that sort of filtering 
you can do it using Object.wontbecalledgetProperty and Object.defineProperty.  
If you just want a fast and comprehensive copy use Object.clone.

The other obvious use case would seem to be adding some "mix-in" behavior to an 
object (some of the descriptions of extend on the web call this "inheritance" 
but it's not how I'd use that term).  This use case is fairly directly 
supported by Object.defineProperties although it is formulated somewhat 
differently.

As I mention in our rationale document, this design isn't just a set of 
individual functions but an attempt at a unified design where we have tried to 
distribute the functional elements across of set of related functions that 
often have multiple uses.  Object.extend is a fine function, particular when 
viewed from the perspective of what can be accomplished using the available ES3 
APIs. However, it isn't something I would simply add as whole cloth to the set 
of functions we have already worked out.  That would mostly just added 
redundant functionality and in a manner that wasn't particularly consistent 
with the other functions we have defined.  Instead, if we added it we would 
potentially refactor the functionality of all of the proposed static Object 
functions to make them stand together as a unit. I'd be happy to discuss 
additional use cases to see try to see if we can find any significant hole in 
our proposal.

Finally, I want to say that my approach to a situation like this where there 
appears to be multiple versions of a similar but not identical function is not 
necessarily to pick one and make everybody else conform.  Instead, I like to 
approach the problem from the perspective of what would have made these various 
functions unnecessary and what primitives would have been useful in 
implementing the assorted variations. If I can provide that then future users 
are unlikely to need to use the old forms and existing user can migrate by 
continuing to use their old API but perhaps reimplementing them using the new 
primitives.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Sayre
Sent: Wednesday, July 16, 2008 2:17 PM
To: Mark S. Miller
Cc: es4-discuss@mozilla.org; [EMAIL PROTECTED]
Subject: Re: ES3.1 Object static methods rationale document

Maybe someone could just give the rationale for leaving out Object.extend?

Douglas Crockford wrote that it was considered, but I'm confused since
it looks like you haven't even seen a proposal, and didn't participate
in the discussion to exclude it.

- Rob

2008/7/16 Mark S. Miller <[EMAIL PROTECTED]>:
> On Wed, Jul 16, 2008 at 10:11 AM, Brendan Eich <[EMAIL PROTECTED]> wrote:
>>
>> And? The doc gives rationales for design decisions. What's the
>> rationale for leaving Object.extend out?
>
> If the document needs to give rationales for leaving out each thing we did
> not include, it would be quite a long document. What is the argument for
> adding Object.extend()? A pointer to Resig's message or a prior discussion
> is an adequate response.
>
> --
> Cheers,
> --MarkM
> _______________________________________________
> Es3.x-discuss mailing list
> [EMAIL PROTECTED]
> https://mail.mozilla.org/listinfo/es3.x-discuss
>



--

Robert Sayre

"I would have written a shorter letter, but I did not have the time."
_______________________________________________
Es3.x-discuss mailing list
[EMAIL PROTECTED]
https://mail.mozilla.org/listinfo/es3.x-discuss

_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to