mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Add deep property support to _.has.
This commit is contained in:
@@ -9414,8 +9414,8 @@
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Object
|
* @category Object
|
||||||
* @param {Object} object The object to inspect.
|
* @param {Object} object The object to inspect.
|
||||||
* @param {string} key The key to check.
|
* @param {string} path The path to check.
|
||||||
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
|
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var object = { 'a': 1, 'b': 2, 'c': 3 };
|
* var object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||||
@@ -9423,8 +9423,19 @@
|
|||||||
* _.has(object, 'b');
|
* _.has(object, 'b');
|
||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function has(object, key) {
|
function has(object, path) {
|
||||||
return object ? hasOwnProperty.call(object, key) : false;
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (hasOwnProperty.call(object, path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isKey(path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
path = toPath(path);
|
||||||
|
object = getPath(object, baseSlice(path, 0, -1));
|
||||||
|
return hasOwnProperty.call(object, last(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user