Side navigation
#14614 closed bug (duplicate)
Opened December 06, 2013 06:56PM UTC
Closed December 06, 2013 07:46PM UTC
Extended objects share single array
Reported by: | mwidman@endurancewindpower.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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"].
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