PDA

View Full Version : What is e.which?


Thundor
08-27-2002, 07:37 PM
We are baffled at this phenomenon called "e"

there is this code:
  document.captureEvents(Event.MOUSEUP);
  document.onmouseup = mouseUp;


and then there is the mouseUp function:
  // check for mouseup
  function mouseUp(e) {

All of the sudden there is a magical "e". It not visibly passed in to the function like the mouseUp function seems to accept.

Later it refers to the "e" by using
  button = e.which;

In trying to do some research on this, We've come across a few of these "e"s. Can anyone explain what this strange and mysterious "e" is?:confused:

Thundor.

jkd
08-27-2002, 07:43 PM
Both NS4 and the DOM2 Events interface (so Gecko-based browsers do it too) pass an argument representing the event object to the event listener. Call it e, event, evt, crazyEvent, arguments[0], whatever, it refers to the passed argument.

adios
08-27-2002, 10:43 PM
Just a note: this 'e' thing (the event object) is the equivalent of the window.Event object (window.event property) in Internet Explorer; rather than being statically exposed during the life of each browser event (and then destroyed), it's simply passed around in a predictable fashion. It's automatically passed to any handler function assigned programatically (i.e., in JavaScript); with HTML handler assignments, it simply 'appears' within the handler (as a local variable) and must be assigned explicitly:

<input...onkeypress="return doSomething(event)">

You naturally capture the event object in a parameter variable at the other end, and 'e' seems to be the fave.
which is the NS4 event property equivalent of keyCode (NS6+/moz: keyCode).

http://www.webreference.com/js/column74/7.html