Bug Tracker

Ticket #2447 (closed bug: worksforme)

Opened 6 months ago

Last modified 6 months ago

$.extend overwrites inner objects nstead of extending

Reported by: aercolino Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords:
Cc: Needs: Review

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)

Attachments

Change History

Changed 6 months 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.

Changed 6 months 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.

Changed 6 months ago by davidserduke

  • status changed from new to closed
  • resolution set to worksforme

Reported "not a bug" by author.

Note: See TracTickets for help on using tickets.