diff --git a/lodash.src.js b/lodash.src.js index dca705a0d..34e544565 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -2621,16 +2621,13 @@ } function baseMethod(object, path, args) { - if (object == null) { - return undefined; - } - if (!(isKey(path) || (path in toObject(object)))) { + if (!isKey(path, object)) { path = toPath(path); - object = baseGet(object, baseSlice(path, 0, -1)); + object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); path = last(path); } - var func = object[path]; - return isFunction(func) ? func.apply(object, args) : undefined; + var func = object == null ? object : object[path]; + return func == null ? undefined : func.apply(object, args); } /** @@ -6755,8 +6752,8 @@ result = isLength(length) ? Array(length) : []; baseEach(collection, function(value) { - var func = isFunc ? methodName : (value != null && value[methodName]); - result[++index] = func ? func.apply(value, args) : undefined; + var func = isFunc ? methodName : (value == null ? value : value[methodName]); + result[++index] = func == null ? undefined : func.apply(value, args); }); return result; }); @@ -11251,7 +11248,7 @@ var methodOf = restParam(function(object, args) { return function(path) { - return object == null ? undefined : baseMethod(object, path, args); + return baseMethod(object, path, args); }; }); diff --git a/test/test.js b/test/test.js index eec6e19d4..85cd3fbaf 100644 --- a/test/test.js +++ b/test/test.js @@ -6882,7 +6882,7 @@ }); test('should not error on elements with missing properties', 1, function() { - var objects = _.map(falsey.concat(_.constant(1)), function(value) { + var objects = _.map([null, undefined, _.constant(1)], function(value) { return { 'a': value }; });