Mangler.merge() - DarthJDG/Mangler.js GitHub Wiki
Copies properties from one object to another. Also works with arrays of objects.
Mangler.merge(destination, source)| Parameter | Type | Default | Description |
|---|---|---|---|
| destination | Object Array.Object |
The object or array of objects to merge properties of source into. |
|
| source | Object Array.Object |
The object or array of objects from which to copy properties. |
Returns destination.
Copies all top-level properties of source object into destination. The source object will not be modified in any way. If a property with the same name already exists in destination, it will be overwritten.
Note that Mangler.merge() does not create a deep copy of the source object, e.g. if you copy a property .prop with an object reference, then both source.prop and destination.prop will reference the same object. To create a deep copy, see Mangler.clone().
a = { firstname: 'John', lastname: 'Bond' };
b = { firstname: 'James', role: 'Secret Agent' };
Mangler.merge(a, b);
/*
a = { firstname: 'James', lastname: 'Bond', role: 'Secret Agent' }
b = { firstname: 'James', role: 'Secret Agent' }
*/Both the destination and source parameters can be either an object or an array of objects. Depending on the type of the parameters, it will do one of the following:
-
merge(object, object)will copy object properties from source to destination. -
merge(object, array)will copy object properties from all source objects to destination in order. -
merge(array, object)will copy object properties from source into all destination objects -
merge(array, array)will copy object properties from all source objects into destination objects with matching array indices. If source has more items, extra items will be ignored. If destination has more items, extra items are unchanged.