Side navigation
#5427 closed bug ()
Opened October 30, 2009 01:49AM UTC
Closed November 11, 2010 11:09PM UTC
$.extend(false, target, obj) doesn't extend target itself
| Reported by: | gminuses | Owned by: | gminuses |
|---|---|---|---|
| Priority: | low | Milestone: | 1.4 |
| Component: | core | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
After executing the following code:
var target = { a: 1 };
$.extend(false, target, { a: 2 });
target is still { a: 1 };
$.extend incorrectly finds target in its definition:
var target = arguments[0] || {}
Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
skip the boolean and the target
i = 2;
}
Attachments (0)
Change History (4)
Changed October 30, 2009 01:52AM UTC by comment:1
Changed October 30, 2009 02:09AM UTC by comment:2
It can be easily fixed by just removing "|| {}":
var target = arguments[0], ...
The validation of target will be checked in its following code:
if ( typeof target !== "object" && !jQuery.isFunction(target) )
target = {};
Changed October 27, 2010 10:08PM UTC by comment:3
| owner: | → gminuses |
|---|---|
| priority: | major → low |
| status: | new → pending |
Please distill this into a reduced test case on jsFiddle, thanks
Changed November 11, 2010 11:09PM UTC by comment:4
| status: | pending → closed |
|---|
Automatically closed due to 14 days of inactivity.
It has line-breaking issues, repost:
After executing the following code:
var target = { a: 1 }; $.extend(false, target, { a: 2 });target is still { a: 1 };
$.extend incorrectly finds target in its definition:
var target = arguments[0] {} // Handle a deep copy situation if ( typeof target === "boolean" ) { deep = target; target = arguments[1] {}; // skip the boolean and the target i = 2; }