On Aug 12, 6:08 pm, Eridius <[EMAIL PROTECTED]> wrote:
> ok let say i have these 2 data objects:
>
> options1 = {url: null, replace_id: null, number: 0}
> options2 = {url: 'test,php', replace_id: 'test'};
>
> How would i merge these two objects so that the 2nd object override the
> first object data is it exists?
One way is jQuery.extend:
function foo( options ) {
options = jQuery.extend( { somevar:'abc', anothervar:'def' },
options );
...
}
foo( { somevar:'ghi' } );
In this case, inside foo(), options would be
{somevar:'ghi',anothervar:'def'}.
(You can do the same with an array, though i used an object here out
of habit.)
See:
http://docs.jquery.com/JavaScript#.24.extend.28_target.2C_prop1.2C_propN_.29