From 044291d9409b8e78ed5d3b678f1f19f4f81903b7 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sun, 29 Mar 2015 08:59:42 -0700 Subject: [PATCH] Add deep property support to `_.has`. --- lodash.src.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 959eb6c69..14d03b152 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -9414,8 +9414,8 @@ * @memberOf _ * @category Object * @param {Object} object The object to inspect. - * @param {string} key The key to check. - * @returns {boolean} Returns `true` if `key` is a direct property, else `false`. + * @param {string} path The path to check. + * @returns {boolean} Returns `true` if `path` is a direct property, else `false`. * @example * * var object = { 'a': 1, 'b': 2, 'c': 3 }; @@ -9423,8 +9423,19 @@ * _.has(object, 'b'); * // => true */ - function has(object, key) { - return object ? hasOwnProperty.call(object, key) : false; + function has(object, path) { + 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)); } /**