Hi!
I have written a function that should compare json msg.a and msg.b . The differences are displayed in msg.c. And msg.b is updated with values from msg.a . But I take these values from global variables 1 and 2. After my function is executed, I get the correct result. But, the global variable 2 is updated without my participation, without global.set . how is this possible? Why is this happening? For example, I recorded a video - Youtube
The code of my function
msg.c = {};
for (let key in msg.a) {
if (msg.b.hasOwnProperty(key)) {
if (msg.a[key] !== msg.b[key]) {
msg.c[key] = msg.a[key];
msg.b[key] = msg.a[key];
}
} else {
msg.c[key] = msg.a[key];
msg.b[key] = msg.a[key];
}
}
return msg;
Hello! thanks for your reply. If I understood you correctly, when I do msg.b = global.get(2), I get not a new object with the same data, but a reference to the global object? And when I make changes to the object msg.b, am I actually changing the global object as well? Then how can I make sure that the global object does not change without my instructions (global.set)?