2929 extend: true,
3030 toInt: true,
3131 inherit: true,
32+ merge: true,
3233 noop: true,
3334 identity: true,
3435 valueFn: true,
@@ -318,6 +319,31 @@ function setHashKey(obj, h) {
318319 }
319320}
320321
322+
323+ function baseExtend ( dst , objs , deep ) {
324+ var h = dst . $$hashKey ;
325+
326+ for ( var i = 0 , ii = objs . length ; i < ii ; ++ i ) {
327+ var obj = objs [ i ] ;
328+ if ( ! isObject ( obj ) && ! isFunction ( obj ) ) continue ;
329+ var keys = Object . keys ( obj ) ;
330+ for ( var j = 0 , jj = keys . length ; j < jj ; j ++ ) {
331+ var key = keys [ j ] ;
332+ var src = obj [ key ] ;
333+
334+ if ( deep && isObject ( src ) ) {
335+ if ( ! isObject ( dst [ key ] ) ) dst [ key ] = isArray ( src ) ? [ ] : { } ;
336+ baseExtend ( dst [ key ] , [ src ] , true ) ;
337+ } else {
338+ dst [ key ] = src ;
339+ }
340+ }
341+ }
342+
343+ setHashKey ( dst , h ) ;
344+ return dst ;
345+ }
346+
321347/**
322348 * @ngdoc function
323349 * @name angular.extend
@@ -328,30 +354,45 @@ function setHashKey(obj, h) {
328354 * Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
329355 * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
330356 * by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
331- * Note: Keep in mind that `angular.extend` does not support recursive merge (deep copy).
357+ *
358+ * **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
359+ * {@link angular.merge} for this.
332360 *
333361 * @param {Object } dst Destination object.
334362 * @param {...Object } src Source object(s).
363+ * @param {boolean= } deep if the last parameter is set to `true`, objects are recursively merged
364+ * (deep copy). Defaults to `false`.
335365 * @returns {Object } Reference to `dst`.
336366 */
337367function extend ( dst ) {
338- var h = dst . $$hashKey ;
368+ return baseExtend ( dst , slice . call ( arguments , 1 ) , false ) ;
369+ }
339370
340- for ( var i = 1 , ii = arguments . length ; i < ii ; i ++ ) {
341- var obj = arguments [ i ] ;
342- if ( obj ) {
343- var keys = Object . keys ( obj ) ;
344- for ( var j = 0 , jj = keys . length ; j < jj ; j ++ ) {
345- var key = keys [ j ] ;
346- dst [ key ] = obj [ key ] ;
347- }
348- }
349- }
350371
351- setHashKey ( dst , h ) ;
352- return dst ;
372+ /**
373+ * @ngdoc function
374+ * @name angular.merge
375+ * @module ng
376+ * @kind function
377+ *
378+ * @description
379+ * Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
380+ * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
381+ * by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
382+ *
383+ * Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
384+ * objects, performing a deep copy.
385+ *
386+ * @param {Object } dst Destination object.
387+ * @param {...Object } src Source object(s).
388+ * @returns {Object } Reference to `dst`.
389+ */
390+ function merge ( dst ) {
391+ return baseExtend ( dst , slice . call ( arguments , 1 ) , true ) ;
353392}
354393
394+
395+
355396function toInt ( str ) {
356397 return parseInt ( str , 10 ) ;
357398}
0 commit comments