Skip to content

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

  1. object (对象):目标对象。

    ¥object (Object): The destination object.

  2. sources (...对象):起始位置。

    ¥sources (...Object): The source objects.

  3. [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 }

Lodash v4.17 中文网 - 粤ICP备13048890号