Foros del Web » Programando para Internet » Javascript »

Variables de objeto. Ayuda!!

Estas en el tema de Variables de objeto. Ayuda!! en el foro de Javascript en Foros del Web. Hola a todos, tengo una duda que me esta volviendo loco. En un codigo que tengo creo un objeto y la variable this en cualquier ...
  #1 (permalink)  
Antiguo 27/01/2008, 04:55
 
Fecha de Ingreso: marzo-2007
Mensajes: 135
Antigüedad: 17 años, 1 mes
Puntos: 0
Pregunta Variables de objeto. Ayuda!!

Hola a todos, tengo una duda que me esta volviendo loco.
En un codigo que tengo creo un objeto y la variable this en
cualquier parte refiere al objeto en cuestion, asi es:

Código HTML:
var dragobject={
 z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
 cclass: null,
////////////////////////////////////////////////////////
initialize:function(c){
 dragobject.cclass = c;
 document.onmousedown = this.drag;
 document.onmouseup = function() { this.dragapproved=0 }
},
////////////////////////////////////////////////////////
drag:function(e){
 var evtobj = window.event ? window.event : e;
 this.targetobj = window.event ? event.srcElement : e.target;
 if (this.targetobj.className==dragobject.cclass || this.targetobj.className.indexOf(dragobject.cclass) != -1)
 {
 this.dragapproved = 1;
 if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
 if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
 this.offsetx=parseInt(this.targetobj.style.left);
 this.offsety=parseInt(this.targetobj.style.top);
 this.x=evtobj.clientX;
 this.y=evtobj.clientY;
 if (evtobj.preventDefault)
 evtobj.preventDefault()
 document.onmousemove=dragobject.moveit;
 }
},
//************************************************
moveit:function(e){
	
var evtobj=window.event? window.event : e;
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";
return false;
						}
			}
}
En este codigo, cuando el raton se mueve salta a la funcion moveit()
y el valor 'this' esta definido como el valor del objeto.
Pero he estado haciendo otro programa que se asemeja y en este
caso no reconoce el valor de 'this'.

Alguien me sabe explicar en que casos y el funcionamiento exacto de
estos valores en manejadores de eventos y demas. ....

Gracias muchas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:34.