Modify ↓
Ticket #5427 (closed bug)
$.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: | ||
| Blocking: | Blocked by: |
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:
| {} |
Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] {}; skip the boolean and the target i = 2;
}
Change History
comment:2 Changed 4 years ago by gminuses
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 = {};
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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; }