Good morning, I've encountered a strange behavior of assignments in javascript. The behavior is replicable outside the specific project, here's how to trigger it:
function A_n(){
var u=100;
this.get=function(){
return u;
}
}
function B_n(){
var e={'g':'','f':new A_n()};
this.get=function(){
var result=e;
var tmp=e.f.get();
result.f=tmp;
return result;
}
}
If I called the "get" method of the instance of the class "B_n" the code would return the correct value (the result of the "get" method of the class "A_n"), but without any reason it reassigns this result to the private variable "e " of the instance of "B_n". Proof of the fact that if we called "a.get()" a second time, it would give an error since "e" would no longer be an object of type "A_n".
var a=new B_n();
console.log(a.get());
{g: '', f: 100}
console.log(a.get());
Uncaught TypeError: e.f.get is not a function
at B_n.get (<anonymous>:12:15)
at <anonymous>:1:15
The problem in the project has been worked around, I would be grateful if someone could explain to me what happens. Thank you