Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14614 closed bug (duplicate)

Extended objects share single array

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


I am not sure if this is a bug, a lack of documentation, or a misunderstanding on my part so I apologize in advance.

When using jQuery.extend() to merge 2 objects (obj1, and obj2) into a new empty object (target), any arrays from obj2 are actually shared between instances of target. So if any instance of target modifies the array, all instances see the change.

A code example is worth a thousand words so please check the following jsfiddle: http://jsfiddle.net/WxpSj/1/

I would expect the console output for the array to say just cat? but instead it says ["chicken", "bird", "cat"].

Change History (2)

comment:1 Changed 9 years ago by [email protected]

It appears there was an issue during my submit and it double posted. Please close this issue as a duplicate of http://bugs.jquery.com/ticket/14613

comment:2 Changed 9 years ago by gibson042

Resolution: duplicate
Status: newclosed

Duplicate of #14613.

Note: See TracTickets for help on using tickets.