keysIn.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var baseKeysIn = require('./_baseKeysIn'),
  2. indexKeys = require('./_indexKeys'),
  3. isIndex = require('./_isIndex'),
  4. isPrototype = require('./_isPrototype');
  5. /** Used for built-in method references. */
  6. var objectProto = Object.prototype;
  7. /** Used to check objects for own properties. */
  8. var hasOwnProperty = objectProto.hasOwnProperty;
  9. /**
  10. * Creates an array of the own and inherited enumerable property names of `object`.
  11. *
  12. * **Note:** Non-object values are coerced to objects.
  13. *
  14. * @static
  15. * @memberOf _
  16. * @since 3.0.0
  17. * @category Object
  18. * @param {Object} object The object to query.
  19. * @returns {Array} Returns the array of property names.
  20. * @example
  21. *
  22. * function Foo() {
  23. * this.a = 1;
  24. * this.b = 2;
  25. * }
  26. *
  27. * Foo.prototype.c = 3;
  28. *
  29. * _.keysIn(new Foo);
  30. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  31. */
  32. function keysIn(object) {
  33. var index = -1,
  34. isProto = isPrototype(object),
  35. props = baseKeysIn(object),
  36. propsLength = props.length,
  37. indexes = indexKeys(object),
  38. skipIndexes = !!indexes,
  39. result = indexes || [],
  40. length = result.length;
  41. while (++index < propsLength) {
  42. var key = props[index];
  43. if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  44. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  45. result.push(key);
  46. }
  47. }
  48. return result;
  49. }
  50. module.exports = keysIn;