主题
assignInWith
js
_.assignInWith(object, sources, [customizer])
此方法与 _.assignIn
类似,不同之处在于它接受 customizer
,调用 customizer
可生成分配的值。如果 customizer
返回 undefined
,则赋值由方法处理。customizer
使用五个参数调用:(objValue, srcValue, key, object, source)。
¥This method is like _.assignIn
except that it accepts customizer
which is invoked to produce the assigned values. If customizer
returns undefined
, assignment is handled by the method instead. The customizer
is invoked with five arguments: (objValue, srcValue, key, object, source).
注意:此方法改变 object
。
¥Note: This method mutates object
.
新增于
¥Since
4.0.0
别名
¥Aliases
_.extendWith
参数
¥Arguments
object
(对象):目标对象。¥
object
(Object): The destination object.sources
(...对象):起始位置。¥
sources
(...Object): The source objects.[customizer]
(函数):自定义分配值的函数。¥
[customizer]
(Function): The function to customize assigned values.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
function customizer(objValue, srcValue) {
return _.isUndefined(objValue) ? srcValue : objValue;
}
var defaults = _.partialRight(_.assignInWith, customizer);
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }