added _.merge definitions

This commit is contained in:
Brian Zengel
2013-10-19 00:25:50 -04:00
parent a7b164dda6
commit 2f14772a7a
2 changed files with 152 additions and 1 deletions
+39
View File
@@ -502,6 +502,45 @@ var optionsPartialRight = {
defaultsDeep(optionsPartialRight, _.templateSettings);
/**********
* Objects *
***********/
var mergeNames = {
'stooges': [
{ 'name': 'moe' },
{ 'name': 'larry' }
]
};
var mergeAges = {
'stooges': [
{ 'age': 40 },
{ 'age': 50 }
]
};
_.merge(mergeNames, mergeAges);
// → { 'stooges': [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] }
var mergeFood = {
'fruits': ['apple'],
'vegetables': ['beet']
};
var mergeOtherFood = {
'fruits': ['banana'],
'vegetables': ['carrot']
};
_.merge(mergeFood, mergeOtherFood, function(a, b) {
return _.isArray(a) ? a.concat(b) : undefined;
});
////////////////////////////////////////////////////////////////////////////////////////
//WHAT'S LEFT
////////////////////////////////////////////////////////////////////////////////////////
+113 -1
View File
@@ -1905,7 +1905,119 @@ declare module _ {
/**********
* Objects *
***********/
/**
* Recursively merges own enumerable properties of the source object(s), that don't resolve
* to undefined into the destination object. Subsequent sources will overwrite property
* assignments of previous sources. If a callback is provided it will be executed to produce
* the merged values of the destination and source properties. If the callback returns undefined
* merging will be handled by the method instead. The callback is bound to thisArg and invoked
* with two arguments; (objectValue, sourceValue).
* @param object The destination object.
* @param s1-8 The source object(s)
* @param callback The function to customize merging properties.
* @param thisArg The this binding of callback.
* @return The destination object.
**/
export function merge(
object: any,
s1: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
s4: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
s4: any,
s5: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
s4: any,
s5: any,
s6: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
s4: any,
s5: any,
s6: any,
s7: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;
/**
* @see _.merge
**/
export function merge(
object: any,
s1: any,
s2: any,
s3: any,
s4: any,
s5: any,
s6: any,
s7: any,
s8: any,
callback?: (objectValue: any, sourceValue: any) => any,
thisArg?: any): any;