it might be too late at night already and I might become crazy but how can this be.
I have the following scenario:
var x = {a: [], b: []};
var y = {a: [], b: []};
Model.someFunction(obj1, function(res){
x.a = res;
y.a = res;
Model.someFunction(obj2, function(res){
x.b = res;
y.b = res;
macheWasAnderes();
// Content of both objects:
// x = {a: [punkt1: 20, punkt2: 30}, b: {punkt1: 50, punkt2: 60}]};
// y = {a: [punkt1: 20, punkt2: 30}, b: {punkt1: 50, punkt2: 60}]};
});
});
function macheWasAnderes(){
for(let prop in x){
for(let i = 0; i < x[prop].length; i++){
for(let propa in x[prop][i]){
x[prop][i][propa] = x[prop][i][propa] / 100;
}
}
}
console.log("x", x);
console.log("y", y);
// x = {a: [punkt1: 0.02, punkt2: 0.03}, b: {punkt1: 0.05, punkt2: 0.06}]};
// y = {a: [punkt1: 0.02, punkt2: 0.03}, b: {punkt1: 0.05, punkt2: 0.06}]};
}
As you can see I am receiving some Data from my callbacks of my Model-functions. When these are done I am calling the machWasAnderes() function in order to calculate with my x object. For this example I am just changing dividing it's value by a hundred and saving it that way.
Strangely enough when I print out both objects, the object y also got the calculated values...
How can this be ?
note This is not my exact code. My code is much longer so I have created an simpler copy of my code which contains the issue.