From 11ab3034b154b977abc9f68d48f9932ee6c4ca5e Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 28 Mar 2015 23:56:37 -0400 Subject: [PATCH] Ensure `_.result` calls deep function with correct context. --- lodash.src.js | 6 +++++- test/test.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lodash.src.js b/lodash.src.js index 5876702cf..81dcf70bc 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -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; } diff --git a/test/test.js b/test/test.js index d71befd8b..bbc3a5838 100644 --- a/test/test.js +++ b/test/test.js @@ -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); + }) }()); /*--------------------------------------------------------------------------*/