🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## mergeWith + [link](./mergeWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L11516 "View in source.") + [npm](https://www.npmjs.com/package/lodash.mergewith "See the npm package.") ``` _.mergeWith(object, sources, customizer) ``` 这个方法类似 `_.merge`。 除了它接受一个 `customizer` 决定如何合并。 如果 `customizer` 返回 `undefined` 将会由合并处理方法代替。 ### 参数 1. object (Object) 目标对象 2. sources (...Object) 来源对象 3. customizer (Function) 这个方法决定如何合并 ### 返回值 (Object) 返回对象 ### 示例 ``` function customizer(objValue, srcValue) { if (_.isArray(objValue)) { return objValue.concat(srcValue); } } var object = { 'fruits': ['apple'], 'vegetables': ['beet'] }; var other = { 'fruits': ['banana'], 'vegetables': ['carrot'] }; _.mergeWith(object, other, customizer); // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } ```