@@ -27,15 +27,19 @@ function primitivesLoopSplice(source, target) {
2727}
2828
2929exports . extendFlat = function ( ) {
30- return _extend ( arguments , false , false ) ;
30+ return _extend ( arguments , false , false , false ) ;
3131} ;
3232
3333exports . extendDeep = function ( ) {
34- return _extend ( arguments , true , false ) ;
34+ return _extend ( arguments , true , false , false ) ;
3535} ;
3636
3737exports . extendDeepAll = function ( ) {
38- return _extend ( arguments , true , true ) ;
38+ return _extend ( arguments , true , true , false ) ;
39+ } ;
40+
41+ exports . extendDeepNoArrays = function ( ) {
42+ return _extend ( arguments , true , false , true ) ;
3943} ;
4044
4145/*
@@ -55,7 +59,7 @@ exports.extendDeepAll = function() {
5559 * Warning: this might result in infinite loops.
5660 *
5761 */
58- function _extend ( inputs , isDeep , keepAllKeys ) {
62+ function _extend ( inputs , isDeep , keepAllKeys , noArrayCopies ) {
5963 var target = inputs [ 0 ] ,
6064 length = inputs . length ;
6165
@@ -79,8 +83,13 @@ function _extend(inputs, isDeep, keepAllKeys) {
7983 src = target [ key ] ;
8084 copy = input [ key ] ;
8185
86+ // Stop early and just transfer the array if array copies are disallowed:
87+ if ( noArrayCopies && isArray ( copy ) ) {
88+ target [ key ] = copy ;
89+ }
90+
8291 // recurse if we're merging plain objects or arrays
83- if ( isDeep && copy && ( isPlainObject ( copy ) || ( copyIsArray = isArray ( copy ) ) ) ) {
92+ else if ( isDeep && copy && ( isPlainObject ( copy ) || ( copyIsArray = isArray ( copy ) ) ) ) {
8493 if ( copyIsArray ) {
8594 copyIsArray = false ;
8695 clone = src && isArray ( src ) ? src : [ ] ;
@@ -89,7 +98,7 @@ function _extend(inputs, isDeep, keepAllKeys) {
8998 }
9099
91100 // never move original objects, clone them
92- target [ key ] = _extend ( [ clone , copy ] , isDeep , keepAllKeys ) ;
101+ target [ key ] = _extend ( [ clone , copy ] , isDeep , keepAllKeys , noArrayCopies ) ;
93102 }
94103
95104 // don't bring in undefined values, except for extendDeepAll
0 commit comments