您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

34 行
753 B

4 年前
  1. var baseHasIn = require('./_baseHasIn'),
  2. hasPath = require('./_hasPath');
  3. /**
  4. * Checks if `path` is a direct or inherited property of `object`.
  5. *
  6. * @static
  7. * @memberOf _
  8. * @since 4.0.0
  9. * @category Object
  10. * @param {Object} object The object to query.
  11. * @param {Array|string} path The path to check.
  12. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13. * @example
  14. *
  15. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  16. *
  17. * _.hasIn(object, 'a');
  18. * // => true
  19. *
  20. * _.hasIn(object, 'a.b');
  21. * // => true
  22. *
  23. * _.hasIn(object, ['a', 'b']);
  24. * // => true
  25. *
  26. * _.hasIn(object, 'b');
  27. * // => false
  28. */
  29. function hasIn(object, path) {
  30. return object != null && hasPath(object, path, baseHasIn);
  31. }
  32. module.exports = hasIn;