_baseHas.js 885 B

1234567891011121314151617181920212223242526
  1. var getPrototype = require('./_getPrototype');
  2. /** Used for built-in method references. */
  3. var objectProto = Object.prototype;
  4. /** Used to check objects for own properties. */
  5. var hasOwnProperty = objectProto.hasOwnProperty;
  6. /**
  7. * The base implementation of `_.has` without support for deep paths.
  8. *
  9. * @private
  10. * @param {Object} [object] The object to query.
  11. * @param {Array|string} key The key to check.
  12. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  13. */
  14. function baseHas(object, key) {
  15. // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
  16. // that are composed entirely of index properties, return `false` for
  17. // `hasOwnProperty` checks of them.
  18. return object != null &&
  19. (hasOwnProperty.call(object, key) ||
  20. (typeof object == 'object' && key in object && getPrototype(object) === null));
  21. }
  22. module.exports = baseHas;