Problem with closure on event object in Firefox

P

petermichaux

Hi,

I have attached an example below that is causing me trouble in Firefox
but not in Safari or Opera. I am trying to create a closure on the
event object in the handleMouseDown function. In Firefox, when the
startDrag function runs, the e object has all the correct properties
but not the correct values.

Any ideas what I have done wrong? If this is a known Firefox bug is
there a standard workaround?

Thanks,
Peter

<html>
<head>

<script type="text/javascript">

function MyObj() {
var thisC = this;
document.getElementById("myDiv").addEventListener("mousedown",
function(e){thisC.handleMouseDown(e);},
false);
};

MyObj.prototype.handleMouseDown = function(e) {
alert(e.pageX + ", " + e.pageY); // for example, outputs 376,
20
var thisC = this;
setTimeout(function() {thisC.startDrag(e);}, 1000);
};

MyObj.prototype.startDrag = function(e) {
alert(e.pageX + ", " + e.pageY); // in Firefox always outputs 0, 0
};

</script>

</head>

<body onload="var myObj = new MyObj();">

<div id="myDiv" style="background-color:lightblue;">
my div
</div>

</body>
</html>
 
M

Martin Honnen

I have attached an example below that is causing me trouble in Firefox
but not in Safari or Opera. I am trying to create a closure on the
event object in the handleMouseDown function. In Firefox, when the
startDrag function runs, the e object has all the correct properties
but not the correct values.

Any ideas what I have done wrong? If this is a known Firefox bug is
there a standard workaround?

Looks like a bug to me, event exists with current Mozilla trunk builds.
I have posted in the Mozilla DOM group
<http://groups.google.com/group/mozi...6140a/c7051398c494f5d4?hl=en#c7051398c494f5d4>
to find out more, will probably file a bug on bugzilla tomorrow when I
find the time and noone in the DOM group knows of an existing bug report.

Not sure about a workaround other then storing the properties you need
in your own object.
 
P

petermichaux

Martin said:
Looks like a bug to me, event exists with current Mozilla trunk builds.
I have posted in the Mozilla DOM group
<http://groups.google.com/group/mozi...6140a/c7051398c494f5d4?hl=en#c7051398c494f5d4>
to find out more, will probably file a bug on bugzilla tomorrow when I
find the time and noone in the DOM group knows of an existing bug report.

Great. Thanks. I didn't know if it was me and I was just getting lucky
with Safari and Opera or if the problem really was Firefox.
Not sure about a workaround other then storing the properties you need
in your own object.

I have done this and it works fine for what I need.

Thanks again.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top