toPlainObject.js 726 B

12345678910111213141516171819202122232425262728293031
  1. var baseCopy = require('../internal/baseCopy'),
  2. keysIn = require('../object/keysIn');
  3. /**
  4. * Converts `value` to a plain object flattening inherited enumerable
  5. * properties of `value` to own properties of the plain object.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @category Lang
  10. * @param {*} value The value to convert.
  11. * @returns {Object} Returns the converted plain object.
  12. * @example
  13. *
  14. * function Foo() {
  15. * this.b = 2;
  16. * }
  17. *
  18. * Foo.prototype.c = 3;
  19. *
  20. * _.assign({ 'a': 1 }, new Foo);
  21. * // => { 'a': 1, 'b': 2 }
  22. *
  23. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  24. * // => { 'a': 1, 'b': 2, 'c': 3 }
  25. */
  26. function toPlainObject(value) {
  27. return baseCopy(value, keysIn(value));
  28. }
  29. module.exports = toPlainObject;