Ensure _.result calls deep function with correct context.

This commit is contained in:
Justin Ridgewell
2015-03-28 23:56:37 -04:00
committed by jdalton
parent c594bda77f
commit 11ab3034b1
2 changed files with 13 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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);
})
}());
/*--------------------------------------------------------------------------*/