Currently, I am working on a TestComplete (UI testing) project that involves JavaScript. In an attempt to store class references in JSON, I have encountered issues with my code not functioning as expected. This has led me to suspect that there may be a misunderstanding regarding how JavaScript manages class references within JSON objects. Below is the snippet of code that outlines my thought process:
class MyClass {
constructor() {
this.name = "ClassName";
}
}
function print_name(str_name) {
console.log(str_name);
}
let my_json = {
"keyOne": [
MyClass
]
};
let class_ref = my_json["keyOne"][0];
print_name(class_ref.name);
I am puzzled as to why the print_name function fails to output the "name" property of the MyClass object. Can anyone shed light on why this might be happening?