keys.js 591 B

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