I have the following problem in event handlers in Javascript. I have an object that has a mousemove event handler.
function MyObject(){ }
function MyObject.prototype = {
currentMousePosition: null,
onMouseMove: function(ev){
this.currentMousePosition = this.getCoordinates(ev);
},
getCoordinates: function(ev){
if (ev.pageX || ev.pageY)
return { x: ev.pageX, y: ev.pageY };
return { x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop };
}
};
The problem I'm trying to solve is resolving the context of the object. In my onMouseMove function, the currentMousePosition property is assigned. Naturally, this will not work, because it is a static function that handles the mousemove event.
What I'm looking for is a method / method for passing the context of an object using my event handler. The best example I can come up with is the Google Maps API function GEvent.bind (). With it, you can pass an object with the function that you want to run on the specified event. I am basically looking for the same thing.