origen of idea:
It always happens that without realizing it, we instantiate a variable and forget that we are not really defining a copy, but a pointer. this can be programmatic problem when dealing with an array of objects. I have the doubt which is the best solution to this. in the same way, propose a syntax to solve it.
the clon keyword, which would basically do a json.stringify and a json.parse together
clon myClonedVar = myComplexObject; // equal to JSON.parse(JSON.stringify(myComplexObject)); myClonedVar.car.color = "red"; myClonedVar.car.color == myComplexObject.car.color; // false
I understand that it is not a syntax problem, but I would like to know your opinions and solutions when we talk about complex objects
my favorite solution is and I think the most effective is:
let myClonedVar = JSON.parse(JSON.stringify(myComplexObject));
but it consumes many resources