mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Ensure _.result calls deep function with correct context.
This commit is contained in:
committed by
jdalton
parent
c594bda77f
commit
11ab3034b1
@@ -9820,7 +9820,11 @@
|
||||
* // => 'busy'
|
||||
*/
|
||||
function result(object, path, defaultValue) {
|
||||
var value = object == null ? undefined : getProperty(object, path);
|
||||
path = toPath(path);
|
||||
if (path.length > 1) {
|
||||
object = getPath(object, dropRight(path));
|
||||
}
|
||||
var value = getProperty(object, last(path));
|
||||
if (typeof value == 'undefined') {
|
||||
value = defaultValue;
|
||||
}
|
||||
|
||||
@@ -12497,6 +12497,14 @@
|
||||
var actual = _.result(object, 'd', object.c);
|
||||
strictEqual(actual, 1);
|
||||
});
|
||||
|
||||
test('should call deep property method with correct context', 1, function() {
|
||||
var value = {
|
||||
'deep': object
|
||||
};
|
||||
|
||||
strictEqual(_.result(value, ['deep', 'c']), 1);
|
||||
})
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user