_copyObject.js 816 B

12345678910111213141516171819202122232425262728293031
  1. var assignValue = require('./_assignValue');
  2. /**
  3. * Copies properties of `source` to `object`.
  4. *
  5. * @private
  6. * @param {Object} source The object to copy properties from.
  7. * @param {Array} props The property identifiers to copy.
  8. * @param {Object} [object={}] The object to copy properties to.
  9. * @param {Function} [customizer] The function to customize copied values.
  10. * @returns {Object} Returns `object`.
  11. */
  12. function copyObject(source, props, object, customizer) {
  13. object || (object = {});
  14. var index = -1,
  15. length = props.length;
  16. while (++index < length) {
  17. var key = props[index];
  18. var newValue = customizer
  19. ? customizer(object[key], source[key], key, object, source)
  20. : source[key];
  21. assignValue(object, key, newValue);
  22. }
  23. return object;
  24. }
  25. module.exports = copyObject;