Im trying to override a class with one that's in other file, the code works this way: Page is loaded One of the files containing the class is added to the head via:
let script = document.createElement("script");
script.src = "./themes/" + thm + "/theme.js";
script.type = "text/javascript";
document.head.appendChild(script);
The content of the theme.js is the following:
class theme_obj{
fn1(){
console.log("Im thm1")
}
fn2(){
}
}
var theme = new theme_obj();
So with the previous in mind, this is the problem. What i want to do, is change the path of theme.js to other ones with the same structure to execute theme.fn1() and so on, but what I get is that theme.fn1() returns the value of the element that the webpage loaded with or was first added, and not the one that its "under use".
How do I fix it? I have been looking for class override, function override, but nothing worked for me. The temporal solution that I found is to reload the page whenever I change the theme but its not ideal