deepFillIn.js 909 B

123456789101112131415161718192021222324252627282930313233
  1. var forOwn = require('./forOwn');
  2. var isPlainObject = require('../lang/isPlainObject');
  3. /**
  4. * Deeply copy missing properties in the target from the defaults.
  5. */
  6. function deepFillIn(target, defaults){
  7. var i = 0,
  8. n = arguments.length,
  9. obj;
  10. while(++i < n) {
  11. obj = arguments[i];
  12. if (obj) {
  13. // jshint loopfunc: true
  14. forOwn(obj, function(newValue, key) {
  15. var curValue = target[key];
  16. if (curValue == null) {
  17. target[key] = newValue;
  18. } else if (isPlainObject(curValue) &&
  19. isPlainObject(newValue)) {
  20. deepFillIn(curValue, newValue);
  21. }
  22. });
  23. }
  24. }
  25. return target;
  26. }
  27. module.exports = deepFillIn;