has.js 552 B

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