Class Index | File Index

Classes


Function Namespace objectMerge


Defined in: <src/object-merge.js>.

Function Namespace Summary
Constructor Attributes Constructor Name and Description
 
objectMerge(opts, shadows)
Merges JavaScript objects recursively without altering the objects merged.
Method Summary
Method Attributes Method Name and Description
<static>  
objectMerge.createOptions(opts)
Creates a new options object suitable for use with objectMerge.
Function Namespace Detail
objectMerge(opts, shadows)
Merges JavaScript objects recursively without altering the objects merged.
Author: Matthew Kastor.
 var objectMerge = require('object-merge');
 var x = {
     a : 'a',
     b : 'b',
     c : {
         d : 'd',
         e : 'e',
         f : {
             g : 'g'
         }
     }
 };
 var y = {
     a : '`a',
     b : '`b',
     c : {
         d : '`d'
     }
 };
 var z = {
     a : {
         b : '``b'
     },
     fun : function foo () {
         return 'foo';
     },
     aps : Array.prototype.slice
 };
 var out = objectMerge(x, y, z);
 // out.a will be {
 //         b : '``b'
 //     }
 // out.b will be '`b'
 // out.c will be {
 //         d : '`d',
 //         e : 'e',
 //         f : {
 //             g : 'g'
 //         }
 //     }
 // out.fun will be a clone of z.fun
 // out.aps will be equal to z.aps
Parameters:
{ObjectMergeOptions} opts Optional
An options object created by objectMerge.createOptions. Options must be specified as the first argument and must be an object created with createOptions or else the object will not be recognized as an options object and will be merged instead.
{Object} shadows
[[shadows]...] One or more objects to merge. Each argument given will be treated as an object to merge. Each object overwrites the previous objects descendant properties if the property name matches. If objects properties are objects they will be merged recursively as well.
Returns:
{Object} Returns a single merged object composed from clones of the input objects.
Method Detail
<static> {ObjectMergeOptions} objectMerge.createOptions(opts)
Creates a new options object suitable for use with objectMerge.
 var opts = objectMerge.createOptions({
     depth : 2,
     throwOnCircularRef : false
 });
 var obj1 = {
     a1 : {
         a2 : {
             a3 : {}
         }
     }
 };
 var obj2 = {
     a1 : {
         a2 : {
             a3 : 'will not be in output'
         },
         a22 : {}
     }
 };
 objectMerge(opts, obj1, obj2);
Parameters:
{Object} opts Optional
An object specifying the options.
{Object} opts.depth Optional, Default: false
Specifies the depth to traverse objects during merging. If this is set to false then there will be no depth limit.
{Object} opts.throwOnCircularRef Optional, Default: true
Set to false to suppress errors on circular references.
Returns:
{ObjectMergeOptions} Returns an instance of ObjectMergeOptions to be used with objectMerge.

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Dec 25 2013 14:53:45 GMT-0500 (Eastern Standard Time)