Object.define ==> Object.mixin??

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Dec 12 13:23:37 PST 2012


I think the latter should replace the previous as overwrite and would not
care much about same property name with only a getter VS only a setter. If
a developer wants both it can use mixin() to define the descriptor.

Back to Nicolas third parameter, true is not as powerful as a
function(target, name, newDescriptor) => objectDescriptor that will
eventually let a developer decide if the newDescriptor should be used or
the old one, regardless possible errors caused if
target.getOwnPropertyDescriptor(name) cannot be overwritten . In this case
the developer might intercept the case and decide if merge descriptors
retrieving the currentOne, if any, return the current one, if any, or
return the new one regardless.

Thoughts?


On Wed, Dec 12, 2012 at 11:13 AM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:

>
> On Dec 12, 2012, at 10:10 AM, John J Barton wrote:
>
> On Wed, Dec 12, 2012 at 10:05 AM, Allen Wirfs-Brock <allen at wirfs-brock.com
> > wrote:
>
>>
>> On Dec 12, 2012, at 9:50 AM, John J Barton wrote:
>> ...
>> > But most of all we want this feature to land and not just spin around
>> here.
>> >
>> > jjb
>>
>> As Object.mixin or as Object.define??
>>
>
> Object.mixin
>
>
> What should be the effect of trying to "mixin" a property that already
> exists (as an own property) of the target object.
>
> Object.define(target,src) would presumably have redefined such properties
> using the Object.defineProperty rules. Is that what Object.mixin should do.
>  It could, have different rules.
>
> For example, it could simply replace an existing target property (if the
> existing property is configurable).  Or it could skip existing properties
> or throw an error if a property exists.
>
> Replace is attractive, but it may or may not be what you want for accessor
> properties.  Consider:
>
> var objTarget = {get foo() {/*target*/...}});
> Object.mixin(objTarget, {set foo(v) {/*src*/...}});
>
> after the mixin do you want objTarget to look like:
>    {set foo(v) {/*src*/...}}   //replace semantics gives you this
> or
>    {set foo(v) {/*src*/...},
>     get foo() {/*target*/...} }  //Object.defineProperty semantics gives
> you this
>
> Allen
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121212/f074f83c/attachment.html>


More information about the es-discuss mailing list