keys.js 565 B

12345678910111213141516
  1. import isObject from './isObject.js';
  2. import { nativeKeys, hasEnumBug } from './_setup.js';
  3. import has from './_has.js';
  4. import collectNonEnumProps from './_collectNonEnumProps.js';
  5. // Retrieve the names of an object's own properties.
  6. // Delegates to **ECMAScript 5**'s native `Object.keys`.
  7. export default function keys(obj) {
  8. if (!isObject(obj)) return [];
  9. if (nativeKeys) return nativeKeys(obj);
  10. var keys = [];
  11. for (var key in obj) if (has(obj, key)) keys.push(key);
  12. // Ahem, IE < 9.
  13. if (hasEnumBug) collectNonEnumProps(obj, keys);
  14. return keys;
  15. }