assignIn.js 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var copyObject = require('./_copyObject'),
  2. createAssigner = require('./_createAssigner'),
  3. keysIn = require('./keysIn');
  4. /**
  5. * This method is like `_.assign` except that it iterates over own and
  6. * inherited source properties.
  7. *
  8. * **Note:** This method mutates `object`.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 4.0.0
  13. * @alias extend
  14. * @category Object
  15. * @param {Object} object The destination object.
  16. * @param {...Object} [sources] The source objects.
  17. * @returns {Object} Returns `object`.
  18. * @see _.assign
  19. * @example
  20. *
  21. * function Foo() {
  22. * this.a = 1;
  23. * }
  24. *
  25. * function Bar() {
  26. * this.c = 3;
  27. * }
  28. *
  29. * Foo.prototype.b = 2;
  30. * Bar.prototype.d = 4;
  31. *
  32. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  33. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  34. */
  35. var assignIn = createAssigner(function(object, source) {
  36. copyObject(source, keysIn(source), object);
  37. });
  38. module.exports = assignIn;