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