I'd vote for replacing duplicate properties by default (as I tend to see
this as the common case). That being said, the mixin functions I use
tend to have an optional third argument that let's you change that
behavior, such as:
// regular
Object.mixin(receiver,supplier);
// safe
Object.mixin(receiver, supplier, true);
-N
On 12/12/2012 11:13 AM, Allen Wirfs-Brock 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
<al...@wirfs-brock.com <mailto:al...@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@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
--
___________________________
Nicholas C. Zakas
http://www.nczonline.net
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss