mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Ensure _.method aligns with _.invoke.
This commit is contained in:
@@ -2621,16 +2621,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function baseMethod(object, path, args) {
|
function baseMethod(object, path, args) {
|
||||||
if (object == null) {
|
if (!isKey(path, object)) {
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (!(isKey(path) || (path in toObject(object)))) {
|
|
||||||
path = toPath(path);
|
path = toPath(path);
|
||||||
object = baseGet(object, baseSlice(path, 0, -1));
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||||
path = last(path);
|
path = last(path);
|
||||||
}
|
}
|
||||||
var func = object[path];
|
var func = object == null ? object : object[path];
|
||||||
return isFunction(func) ? func.apply(object, args) : undefined;
|
return func == null ? undefined : func.apply(object, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6755,8 +6752,8 @@
|
|||||||
result = isLength(length) ? Array(length) : [];
|
result = isLength(length) ? Array(length) : [];
|
||||||
|
|
||||||
baseEach(collection, function(value) {
|
baseEach(collection, function(value) {
|
||||||
var func = isFunc ? methodName : (value != null && value[methodName]);
|
var func = isFunc ? methodName : (value == null ? value : value[methodName]);
|
||||||
result[++index] = func ? func.apply(value, args) : undefined;
|
result[++index] = func == null ? undefined : func.apply(value, args);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
@@ -11251,7 +11248,7 @@
|
|||||||
|
|
||||||
var methodOf = restParam(function(object, args) {
|
var methodOf = restParam(function(object, args) {
|
||||||
return function(path) {
|
return function(path) {
|
||||||
return object == null ? undefined : baseMethod(object, path, args);
|
return baseMethod(object, path, args);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6882,7 +6882,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should not error on elements with missing properties', 1, function() {
|
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 };
|
return { 'a': value };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user