Make sure to do a deep copy on arrays. #5750

This commit is contained in:
Filipe Fortes 2010-01-05 05:25:14 +08:00 committed by John Resig
parent 6861b5d4eb
commit 0d1a2c1b11
2 changed files with 11 additions and 6 deletions

View file

@ -316,10 +316,10 @@ jQuery.extend = jQuery.fn.extend = function() {
continue;
}
// Recurse if we're merging object literal values
if ( deep && copy && jQuery.isPlainObject(copy) ) {
// Don't extend not object literals
var clone = src && jQuery.isPlainObject(src) ? src : {};
// Recurse if we're merging object literal values or arrays
if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) {
var clone = src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ? src
: jQuery.isArray(copy) ? [] : {};
// Never move original objects, clone them
target[ name ] = jQuery.extend( deep, clone, copy );