💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## assignWith + [link](./assignWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L10797 "View in source.") + [npm](https://www.npmjs.com/package/lodash.assignwith "See the npm package.") ``` _.assignWith(object, sources, [customizer]) ``` 这个方法类似 `_.assign`。 除了它接受一个 customizer`决定如何分配值。 如果`customizer`返回`undefined`将会由分配处理方法代替。`customizer` 会传入5个参数:(objValue, srcValue, key, object, source)。 **注意:** 这方法会改变源对象 ### 参数 1. object (Object) 目标对象 2. sources (...Object) 来源对象 3. [customizer] (Function) 这个函数决定分配的值 ### 返回值 (Object) 返回对象 ### 示例 ``` function customizer(objValue, srcValue) { return _.isUndefined(objValue) ? srcValue : objValue; } var defaults = _.partialRight(_.assignWith, customizer); defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); // => { 'a': 1, 'b': 2 } ```