Skip to main content

Bug Tracker

Side navigation

#14275 closed bug (notabug)

Opened August 20, 2013 02:22PM UTC

Closed August 20, 2013 05:43PM UTC

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:

jQuery.extend demonstrates unexpected behavior. Fields from objectN with value of ''undefined'' does not copy to target object.


var target = {};
var object1 = {
    undefined_field: undefined, 
    null_field: null
var result = $.extend({}, target, object1);

for (var field in target)
    console.log(field, target[field]);

for (var field in object1)
    console.log(field, object1[field]);

for (var field in result)
    console.log(field, result[field]);


> 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.

Attachments (0)
Change History (2)

Changed August 20, 2013 02:40PM UTC by comment:1

See examples by links below:

jQuery 1.8.3

jQuery 1.10.2

jQuery 2.0.3

''* it's recommended to use, but it's down now''

Changed August 20, 2013 05:43PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

As documented in :

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.