UNPKG

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