Object.each(o1, function(value, key){
  if (key in o2) o1[key] = o2[key];
});

On Nov 12, 12:39 pm, "Matthew Hazlett" <[email protected]> wrote:
> Something like this?
>
> srcArray = [10, 20, 30, 100, 60];
> cmpArray = [10, 3, 25, 100];
>
> var result = cmpArray.filter(function(item, index){
>     return srcArray.contains(item);
>
> });
>
> The result array would just contain elements that are in both arrays.  You
> could modify it to support different typs of arrays if you like.
>
>
>
>
>
>
>
> -----Original Message-----
> From: [email protected]
>
> [mailto:[email protected]] On Behalf Of stratboy
> Sent: Friday, November 12, 2010 6:16 AM
> To: MooTools Users
> Subject: [Moo] Re: A kind of 'intersection' object merge?
>
> Well, merge does 2 things: override existing props, and eventually add the
> new ones. I need only the override. So it's a 'subset' of the merge
> functionality.
>
> On 12 Nov, 11:35, Vito Tafuni <[email protected]> wrote:
> > I think merge is not semantically correct!
> > you are simply extracting from o2 using o1 like a template... where'
> > the merge!?!
>
> > At max I could expect from
> > merge(o1,o2) -> { a:1, b:2, c:3, d:4, e:5 }
> > merge(o2,o1) -> { a:1.2, b:2.2, c:3.2, d:4, e:5 }
>
> > --
> > -----------
> > Tafuni Vito
> > [email protected]
> > ---------------------------------------------
> > "Verba volant, scripta manent... data corrupted"
>
> > 2010/11/12 stratboy <[email protected]>
>
> > > Hi! Suppose this:
>
> > > var o1 = { a:1, b:2, c:3 }
> > > var o2 = { a:1.2, b:2.2, c:3.2, d:4, e:5 }
>
> > > I want some kind of merge operation that merges only the props with
> > > same key, so in the end I've got this:
>
> > > var o3 =  { a:1.2, b:2.2, c:3.2 }
>
> > > I know I can do it with a couple of passages, for ex. by using
> > > Object.subset first. Though, I'd like to know i there's some other
> > > smart way. It would quite handy if in the future releases of
> > > mootools there will be a thing like:
>
> > > Object.merge(o1,o2[,true]);
>
> > > where the last option is for using only the common keys or not.
>
> > > :) How about?

Reply via email to