ciao a tutti io penso di avere un problema di scope con degli oggetti
codice:
function element(obj, status){
this.obj = obj;
this.status = status;
this.onload = this.instance()
}
element.prototype.instance = function() {
this.action()
this.obj.childNodes[0].addEventListener("click", this.action, false);
}
element.prototype.action = function() {
if(this.status == true){
alert(this.status)
childs = this.obj.childNodes;
for(i=1; i<childs.length; i++){
childs[i].className = "hidden";
}
this.status = false;
alert(this.status)
}
else if(this.status == false){
childs = this.childNodes;
for(i=1; i<childs.length; i++){
childs[i].className = "normal";
}
this.status = true;
}
else{ alert(this.status); }
}
function list() {
var elements = document.getElementsByTagName("div");
for(x=0; x<elements.length; x++){
if(elements[x].getAttribute("class") == "block"){
new element(elements[x],true);
/*childs = elements[x].childNodes;
for(i=0; i<childs.length; i++){
alert(childs[i].innerHTML);
}*/
}
}
}
onload = function(){ list(); }
in pratica quando aggiungo l'evento via listener this.action lo faccio sull'oggetto inferiore, quello del nodo 1, invece io vogloi chiamarlo sul oggetto da me istanziato, qualcuno mi sa aiutare?
tks