_customDefaultsAssignIn.js 934 B

123456789101112131415161718192021222324252627282930
  1. var eq = require('./eq');
  2. /** Used for built-in method references. */
  3. var objectProto = Object.prototype;
  4. /** Used to check objects for own properties. */
  5. var hasOwnProperty = objectProto.hasOwnProperty;
  6. /**
  7. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  8. * of source objects to the destination object for all destination properties
  9. * that resolve to `undefined`.
  10. *
  11. * @private
  12. * @param {*} objValue The destination value.
  13. * @param {*} srcValue The source value.
  14. * @param {string} key The key of the property to assign.
  15. * @param {Object} object The parent object of `objValue`.
  16. * @returns {*} Returns the value to assign.
  17. */
  18. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  19. if (objValue === undefined ||
  20. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  21. return srcValue;
  22. }
  23. return objValue;
  24. }
  25. module.exports = customDefaultsAssignIn;