Thanks for your answer!
Actually the "that" solution seems a bit akward... What's the proper way of handling this?
I wanted to create a class containing all the logic I need, but maybe in JS I don't really need that.
Thanks for your answer!
Actually the "that" solution seems a bit akward... What's the proper way of handling this?
I wanted to create a class containing all the logic I need, but maybe in JS I don't really need that.
Mulone
there isn't a perfect way. there is only one word, "this", that javascript uses for OOP and events; you have to dupe/shadow one of them when both are needed.
you can use closure to cleanup the interface and avoid the extra that property, at a slight cost to speed:
Code:
MouseLogger.prototype.grabEvents = (function(){
var that=this;
return function(e) {
if (!e) e = window.event;
if (!e) log.error("grabCoordinates null event",e);
if (e.pageX || e.pageY)
{
that.posx = e.pageX;
that.posy = e.pageY;
}
else if (e.clientX || e.clientY){
that.posx = e.clientX + document.body.scrollLeft;
that.posy = e.clientY + document.body.scrollTop;
}
//log.debug("grabCoordinates",this.posx,this.posy)
if (!that.posx || !that.posy){
log.warn("grabCoordinates null coords");
that.posx = null;
that.posy = null;
}
log.error(that);
that.addGuiEvent(e);
}
}());//end scope wrapper
I used to think that window object supports only few events (onload, onblur, onfocus, onerror, onunload and onbeforeunload [non standard]). I would say that onmousemove should be attached to the document object
Bookmarks