主题
updateWith
js
_.updateWith(object, path, updater, [customizer])
此方法与 _.update
类似,不同之处在于它接受 customizer
,调用 customizer
可生成 path
的对象。如果 customizer
返回 undefined
,则路径创建由方法处理。customizer
使用三个参数来调用:(nsValue, key, nsObject)。
¥This method is like _.update
except that it accepts customizer
which is invoked to produce the objects of path
. If customizer
returns undefined
path creation is handled by the method instead. The customizer
is invoked with three arguments: (nsValue, key, nsObject).
注意:此方法改变 object
。
¥Note: This method mutates object
.
新增于
¥Since
4.6.0
参数
¥Arguments
object
(对象):要查询的对象。¥
object
(Object): The object to modify.path
(数组|字符串):要设置的属性的路径。¥
path
(Array|string): The path of the property to set.updater
(函数):生成更新值的函数。¥
updater
(Function): The function to produce the updated value.[customizer]
(函数):自定义分配值的函数。¥
[customizer]
(Function): The function to customize assigned values.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
var object = {};
_.updateWith(object, '[0][1]', _.constant('a'), Object);
// => { '0': { '1': 'a' } }