assignOwnDefaults.js 950 B

1234567891011121314151617181920212223242526
  1. /** Used for native method references. */
  2. var objectProto = Object.prototype;
  3. /** Used to check objects for own properties. */
  4. var hasOwnProperty = objectProto.hasOwnProperty;
  5. /**
  6. * Used by `_.template` to customize its `_.assign` use.
  7. *
  8. * **Note:** This function is like `assignDefaults` except that it ignores
  9. * inherited property values when checking if a property is `undefined`.
  10. *
  11. * @private
  12. * @param {*} objectValue The destination object property value.
  13. * @param {*} sourceValue The source object property value.
  14. * @param {string} key The key associated with the object and source values.
  15. * @param {Object} object The destination object.
  16. * @returns {*} Returns the value to assign to the destination object.
  17. */
  18. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  19. return (objectValue === undefined || !hasOwnProperty.call(object, key))
  20. ? sourceValue
  21. : objectValue;
  22. }
  23. module.exports = assignOwnDefaults;