Opened 9 years ago
Closed 9 years ago
#14275 closed bug (notabug)
jQuery.extend does not copy fields value fo undefined from objectN to target
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 2.0.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
jQuery.extend demonstrates unexpected behavior. Fields from objectN with value of undefined does not copy to target object.
Example:
var target = {}; var object1 = { undefined_field: undefined, null_field: null }; var result = $.extend({}, target, object1); console.log('target:'); for (var field in target) console.log(field, target[field]); console.log(''); console.log('object1:'); for (var field in object1) console.log(field, object1[field]); console.log(''); console.log('result:'); for (var field in result) console.log(field, result[field]);
Output:
> target: > > object1: > undefined_field undefined > null_field null > > result: > null_field null
Expected output:
> target: > > object1: > undefined_field undefined > null_field null > > result: > undefined_field undefined > null_field null
Bug reproduces with jQuery versions of 1.8.3, 1.10.2, 2.0.3.
Change History (2)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
As documented in http://api.jquery.com/jQuery.extend/ :
Undefined properties are not copied.
We definitely wouldn't want to change documented behavior here, it certainly should be expected by those who read the documentation.
Note: See
TracTickets for help on using
tickets.
See examples by links below:
jQuery 1.8.3
jQuery 1.10.2
jQuery 2.0.3
* it's recommended to use jsFiddle.net, but it's down now