Let's say I have an object with some properties:
const obj = {
key1: 1
key2: 2
}
and I have a function someFunc
that takes a single object as a parameter. I want to pass obj
with some additional parameters, for example
someFunc({
key1: 1
key2: 2
otherKey: 3
})
The problem is that I do not want to change the state obj
. After it has someFunc
been called, it should not contain otherKey
as a property.
This leaves Object.assign
out the question:
let ident = someObj => someObj;
ident(Object.assign(obj, {otherKey: 3}))
console.log(someObj);
Creating a new variable and assigning it otherKey = 3
does the same.
I know that I can use some kind of deep duplication, but this seems like an overly complicated way to solve a rather simple problem.
- , obj1, obj2
, , Object.assign(obj1, obj2)
, . JS, , - ?