has.js 526 B

1234567891011121314151617
  1. import _has from './_has.js';
  2. import toPath from './_toPath.js';
  3. // Shortcut function for checking if an object has a given property directly on
  4. // itself (in other words, not on a prototype). Unlike the internal `has`
  5. // function, this public version can also traverse nested properties.
  6. export default function has(obj, path) {
  7. path = toPath(path);
  8. var length = path.length;
  9. for (var i = 0; i < length; i++) {
  10. var key = path[i];
  11. if (!_has(obj, key)) return false;
  12. obj = obj[key];
  13. }
  14. return !!length;
  15. }