I have the following snippet of code buried deep within a complicated function:
result = {
...result,
mp_mods: {
...result.mp_mods,
Untyped: {
...result.mp_mods.Untyped,
[kitObj.id]: {
num: 2,
level
}
}
}
};
let newVar = {
...result,
mp_mods: {
...result.mp_mods,
Untyped: {
...result.mp_mods.Untyped,
[kitObj.id]: {
num: 2,
level
}
}
}
};
console.log(result.mp_mods);
console.log(newVar.mp_mods);
These two console.logs are producing different results. newVar looks like I want it to, while result still looks the same as it did before I tried to assign a new value to it. It seems to be (undesirably) immutable, due to ... some complicated rule of scope or something?
result was originally declared with let, not const, so that's not the reason. (Too bad, that would have generated a clear error message and been easy to fix.)
Can anyone explain what is going on here? There must be something in my code preceding this snippet that's problematic. But I need to modify result, and I currently can't!