Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

has.js 662B

1234567891011121314151617181920212223
  1. var _setup = require('./_setup.js');
  2. var isArray = require('./isArray.js');
  3. var _has = require('./_has.js');
  4. // Shortcut function for checking if an object has a given property directly on
  5. // itself (in other words, not on a prototype). Unlike the internal `has`
  6. // function, this public version can also traverse nested properties.
  7. function has(obj, path) {
  8. if (!isArray(path)) {
  9. return _has(obj, path);
  10. }
  11. var length = path.length;
  12. for (var i = 0; i < length; i++) {
  13. var key = path[i];
  14. if (obj == null || !_setup.hasOwnProperty.call(obj, key)) {
  15. return false;
  16. }
  17. obj = obj[key];
  18. }
  19. return !!length;
  20. }
  21. module.exports = has;