_assignInDefaults.js 792 B

123456789101112131415161718192021222324252627
  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.
  8. *
  9. * @private
  10. * @param {*} objValue The destination value.
  11. * @param {*} srcValue The source value.
  12. * @param {string} key The key of the property to assign.
  13. * @param {Object} object The parent object of `objValue`.
  14. * @returns {*} Returns the value to assign.
  15. */
  16. function assignInDefaults(objValue, srcValue, key, object) {
  17. if (objValue === undefined ||
  18. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  19. return srcValue;
  20. }
  21. return objValue;
  22. }
  23. module.exports = assignInDefaults;