Side navigation
#6958 closed bug (duplicate)
Opened August 27, 2010 10:13AM UTC
Closed October 03, 2010 08:35PM UTC
$.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 (1)
Changed October 03, 2010 08:35PM UTC by comment:1
priority: | → undecided |
---|---|
resolution: | → duplicate |
status: | new → closed |
Dup of #5991, fixed here: http://github.com/jquery/jquery/commit/694b625c92c764621532dba20cbf943302b52d5a