Javascript global object calls function?
- by Troels
Hello stackoverflow
I have a very odd problem with javascript. My code is rather long so here is an example of the structure and the problem:
var x = new function f() {
this.id = "";
}
function g(obj) {
if (x.id == "") {
...
obj.firstChild.setAttribute("onclick", "javascript:o();");
...
x.id = obj.id;
}
else if (x.id != obj.id) {
...
x.id = "";
g(obj);
}
}
function o() {
...
if (something == something) {
...
}
else {
...
x.id = ""; // if-statement of the g() function is called here?
}
}
As you can see, the if-statement of the g() function is for some reason called or re-run upon x.id being changed. I simply cannot understand this, because they are not in the same scope, and changing a variable should under no circumstances trigger anything?
Any help would be greatly appreciated.