Opened 12 years ago
Closed 12 years ago
#6958 closed bug (duplicate)
$.extend (not deep) copying arrays by reference not cloning
Reported by: | enideo | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4.3 |
Component: | core | Version: | 1.4.2 |
Keywords: | extend array | Cc: | |
Blocked by: | Blocking: |
Description
BUG: as put in the title, see the attachment for the full explanation and examples.
I believe this to be a bug as the behaviour is not as desired: arguments of the extend function, other than target, can be modified if the target is later modified (they are referenced not cloned)
PROPOSED FIX: replace the following lines in the jQuery.extend function:
// Don't bring in undefined values } else if ( copy !== undefined ) { target[ name ] = copy; }
with...
// Don't bring in undefined values } else if ( copy !== undefined ) { target[ name ] = ( jQuery.isArray!==undefined && jQuery.isArray(copy) ) ? target[ name ] = copy.slice(0) : target[ name ] = copy; }
NOTE: it seems necessary to check for the jQuery.isArray function's existence as the jQuery.extend function is called before this has been defined. Those who are more familiar with the rest of the code may be able to come up with a better solution.
Attachments (1)
Change History (2)
Changed 12 years ago by
Attachment: | jqExtendArrayBug.html added |
---|
comment:1 Changed 12 years ago by
Priority: | → undecided |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Example of the bug and fixes