Side navigation
#15246 closed bug (notabug)
Opened September 23, 2014 10:33AM UTC
Closed September 23, 2014 02:16PM UTC
$.extend with deep copy of an array property merges the array instead of replacing it
Reported by: | i23098 | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.11.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If I run $.extend(true, {}, {'a': [1,2,3]}, {'a':[4]}) I would expect the result to be {"a":[4]} as property a should be overwritten instead of merged...
Attachments (0)
Change History (2)
Changed September 23, 2014 10:36AM UTC by comment:1
Changed September 23, 2014 02:16PM UTC by comment:2
resolution: | → notabug |
---|---|
status: | new → closed |
Merging objects and arrays rather than overwriting them is the behavior that differentiates our deep extend from our shallow extend.
http://api.jquery.com/jQuery.extend/:
On a deep
extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not. Deep-extending a cyclical data structure will result in an error. For needs that fall outside of this behavior, write a custom extend method instead, or use a library like lodash.
It also happens in 2.x