_assignValue.js 899 B

1234567891011121314151617181920212223242526272829
  1. var baseAssignValue = require('./_baseAssignValue'),
  2. eq = require('./eq');
  3. /** Used for built-in method references. */
  4. var objectProto = Object.prototype;
  5. /** Used to check objects for own properties. */
  6. var hasOwnProperty = objectProto.hasOwnProperty;
  7. /**
  8. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  9. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10. * for equality comparisons.
  11. *
  12. * @private
  13. * @param {Object} object The object to modify.
  14. * @param {string} key The key of the property to assign.
  15. * @param {*} value The value to assign.
  16. */
  17. function assignValue(object, key, value) {
  18. var objValue = object[key];
  19. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  20. (value === undefined && !(key in object))) {
  21. baseAssignValue(object, key, value);
  22. }
  23. }
  24. module.exports = assignValue;