diff --git src/core.js src/core.js
index 93f04ec..9f9eefb 100644
|
|
jQuery.extend = jQuery.fn.extend = function() { |
313 | 313 | continue; |
314 | 314 | } |
315 | 315 | |
316 | | // Recurse if we're merging object literal values |
317 | | if ( deep && copy && jQuery.isPlainObject(copy) ) { |
318 | | // Don't extend not object literals |
319 | | var clone = src && jQuery.isPlainObject(src) ? src : {}; |
| 316 | // Recurse if we're merging object literal values or arrays |
| 317 | if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) { |
| 318 | var clone = {}; |
| 319 | // Only extend object literals or arrays |
| 320 | if ( src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ) { |
| 321 | clone = src; |
| 322 | // Don't clone an array with an object |
| 323 | } else if ( jQuery.isArray (copy) ) { |
| 324 | clone = []; |
| 325 | } |
320 | 326 | |
321 | 327 | // Never move original objects, clone them |
322 | 328 | target[ name ] = jQuery.extend( deep, clone, copy ); |
diff --git test/unit/core.js test/unit/core.js
index e3adc60..c779e28 100644
|
|
test("jQuery.merge()", function() { |
657 | 657 | }); |
658 | 658 | |
659 | 659 | test("jQuery.extend(Object, Object)", function() { |
660 | | expect(25); |
| 660 | expect(27); |
661 | 661 | |
662 | 662 | var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, |
663 | 663 | options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, |
… |
… |
test("jQuery.extend(Object, Object)", function() { |
667 | 667 | deep1copy = { foo: { bar: true } }, |
668 | 668 | deep2 = { foo: { baz: true }, foo2: document }, |
669 | 669 | deep2copy = { foo: { baz: true }, foo2: document }, |
670 | | deepmerged = { foo: { bar: true, baz: true }, foo2: document }; |
| 670 | deepmerged = { foo: { bar: true, baz: true }, foo2: document }, |
| 671 | arr = [1, 2, 3], |
| 672 | nestedarray = { arr: arr }; |
671 | 673 | |
672 | 674 | jQuery.extend(settings, options); |
673 | 675 | same( settings, merged, "Check if extended: settings must be extended" ); |
… |
… |
test("jQuery.extend(Object, Object)", function() { |
682 | 684 | same( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); |
683 | 685 | equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); |
684 | 686 | |
| 687 | ok( jQuery.extend(true, [], arr) !== arr, "Deep extend of array must clone array" ); |
| 688 | ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" ); |
| 689 | |
685 | 690 | var empty = {}; |
686 | 691 | var optionsWithLength = { foo: { length: -1 } }; |
687 | 692 | jQuery.extend(true, empty, optionsWithLength); |