I basically have an object, but this object will only be filled after user input. But the other classes are using this object also. But then after I fill the object with the real object, it doesn’t get updated in the other classes.
Example :
var x = {
text: null
}
var y = {
text: x.text
}
x.text = 'trlalala';
console.log(y.text);
console.log(x.text);
but when I run it, y.text will print out null. But the value should be updated already. One of my friend told me it’s because y.text copy the structure of x.text instead of the reference. Been stuck for a while. :\
Any input will be appreciated, thanks!
text: x.textlooks at the value ofx.text(a reference tonull) and setsy.textto that.When you say
x.text = 'trlalala', then you change the value ofx.text(so it is a reference to the immutable string'trlalala') but the value ofy.textremains a reference tonull.You would need an intermediate object that you get a reference to if you want to share data like that. (Since then you would be dealing with a reference to an object)