MCPcopy
hub / github.com/lodash/lodash / baseSet

Function baseSet

lodash.js:4025–4057  ·  view source on GitHub ↗

* The base implementation of `_.set`. * * @private * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. * @param {*} value The value to set. * @param {Function} [customizer] The function to customize path creation.

(object, path, value, customizer)

Source from the content-addressed store, hash-verified

4023 * @returns {Object} Returns `object`.
4024 */
4025 function baseSet(object, path, value, customizer) {
4026 if (!isObject(object)) {
4027 return object;
4028 }
4029 path = castPath(path, object);
4030
4031 var index = -1,
4032 length = path.length,
4033 lastIndex = length - 1,
4034 nested = object;
4035
4036 while (nested != null && ++index < length) {
4037 var key = toKey(path[index]),
4038 newValue = value;
4039
4040 if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
4041 return object;
4042 }
4043
4044 if (index != lastIndex) {
4045 var objValue = nested[key];
4046 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4047 if (newValue === undefined) {
4048 newValue = isObject(objValue)
4049 ? objValue
4050 : (isIndex(path[index + 1]) ? [] : {});
4051 }
4052 }
4053 assignValue(nested, key, newValue);
4054 nested = nested[key];
4055 }
4056 return object;
4057 }
4058
4059 /**
4060 * The base implementation of `setData` without support for hot loop shorting.

Callers 4

basePickByFunction · 0.85
baseUpdateFunction · 0.85
setFunction · 0.85
setWithFunction · 0.85

Calls 6

isObjectFunction · 0.85
castPathFunction · 0.85
toKeyFunction · 0.85
customizerFunction · 0.85
isIndexFunction · 0.85
assignValueFunction · 0.85

Tested by

no test coverage detected