Tr*******@gmail.com wrote:
I'm not very knowledgeable with how event listeners or handlers work?
Is that a question?
What difference does window.setTimeout as opposed to setTimeout do?
setTimeout() is not a built-in method; it is a method of Window host objects
and it should be called so.
One is calling a known and well-supported (albeit proprietary)
function-property of the object `window' refers to, the other is calling a
property of the next object in the scope chain that has such a property,
provided that there is such an object and that this property can be called
(otherwise it throws a TypeError exception). In short, the former is more
obvious (as one can see at a glance by/for which object the method is
called), more efficient (as scope chain resolution is faster with a given
object reference), and less error-prone.
and I'm calling the showPopup like this:
<td onmouseover="showPopup(event);"></td>
That changes the meaning of the `event' named argument of showPopup(), of
course. I assumed that you used (DOM Level 0)
refToTDElObj.onmouseover = showPopup;
or (W3C DOM Level 2 Events)
refToTDElObj.addEventListener('...', showPopup, ...);
or (MSHTML DOM)
refToTDElObj.attachEvent('...', showPopup);
instead. As I said, how showPopup() is called is significant.
What I'm also confused about is although you say
alert(globalEvent.type) should
give me an error, it works when I'm still in the showPopup method, and
yet it fails when I call it again in unhideDiv()??
The reason for that is if you pass `event' in an event handler attribute
value, it refers (proprietarily) to the current Event object. Which means
that in the MSHTML DOM the value of the `event' argument (in showPopup) is
not `undefined'. Hence globalEvent.type there does not throw an exception.
The only explanation I have as to why the same lookup threw an exception in
unhideDiv() is that you have indeed a typo there --
| var globalEvevnt;
-- and that this typo is significant. Because that would mean that
globalEvent = event;
in showPopup() would attempt to add a property to an object in the scope
chain, which is not necessarily the Global Object. And then in unhideDiv(),
| globalEvent.type
would be resolved to
undefined.type
which would throw a TypeError. Unless you have posted code less similar to
the code you are actually using.
I recommend instead not to use globally available properties. Quickhack:
function unhideDiv(e)
{
window.alert(e.type);
}
function showPopup(e)
{
window.alert(e.type);
window.setTimeout(function(){ unhideDiv(e); }, 2000);
}
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16