主题
result
js
_.result(object, path, [defaultValue])
此方法类似于 _.get
,只是如果解析的值是一个函数,它会使用其父对象的 this
绑定来调用并返回其结果。
¥This method is like _.get
except that if the resolved value is a function it's invoked with the this
binding of its parent object and its result is returned.
新增于
¥Since
0.1.0
参数
¥Arguments
object
(对象):的反面;¥
object
(Object): The object to query.path
(数组|字符串):要解析的属性的路径。¥
path
(Array|string): The path of the property to resolve.[defaultValue]
(*):undefined
解析值返回的值。¥
[defaultValue]
()*: The value returned forundefined
resolved values.
返回
¥Returns
(*):返回解析后的值。
¥()*: Returns the resolved value.
示例
¥Example
js
var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
_.result(object, 'a[0].b.c1');
// => 3
_.result(object, 'a[0].b.c2');
// => 4
_.result(object, 'a[0].b.c3', 'default');
// => 'default'
_.result(object, 'a[0].b.c3', _.constant('default'));
// => 'default'