deepMixIn.js 758 B

12345678910111213141516171819202122232425262728293031323334
  1. var forOwn = require('./forOwn');
  2. var isPlainObject = require('../lang/isPlainObject');
  3. /**
  4. * Mixes objects into the target object, recursively mixing existing child
  5. * objects.
  6. */
  7. function deepMixIn(target, objects) {
  8. var i = 0,
  9. n = arguments.length,
  10. obj;
  11. while(++i < n){
  12. obj = arguments[i];
  13. if (obj) {
  14. forOwn(obj, copyProp, target);
  15. }
  16. }
  17. return target;
  18. }
  19. function copyProp(val, key) {
  20. var existing = this[key];
  21. if (isPlainObject(val) && isPlainObject(existing)) {
  22. deepMixIn(existing, val);
  23. } else {
  24. this[key] = val;
  25. }
  26. }
  27. module.exports = deepMixIn;