Bug Tracker

Opened 15 years ago

Closed 15 years ago

#2447 closed bug (worksforme)

$.extend overwrites inner objects nstead of extending

Reported by: aercolino Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:

Description

After writing:

var z = $.extend( {a: 1, b: {c: {d: 2}}, f: 5}, {a: 3, b: {c: {e: 4}}} );

I'd expect:

z == {a: 3, b: {c: {d: 2, e: 4}}, f: 5}

But I get:

z == {a: 3, b: {c: {e: 4}}, f: 5}

(Undocumented 'deep' parameter only works for the 1st level)

Change History (3)

comment:1 Changed 15 years ago by aercolino

I think the fix could be this (line 599 of jquery-1.2.3.js)

- target[ name ] = jQuery.extend( target[ name ], options[ name ] );
+ target[ name ] = jQuery.extend( true, target[ name ], options[ name ] );

In fact, the 'deep' (true) argument should be propagated to recursion steps.

comment:2 Changed 15 years ago by aercolino

OK, I now understand that $.extend works as expected, by overwriting any matching property in the target, so this is not a bug, but a 'true' deep option should not change to 'false' after its first recursion step.

comment:3 Changed 15 years ago by davidserduke

Resolution: worksforme
Status: newclosed

Reported "not a bug" by author.

Note: See TracTickets for help on using tickets.