Jump to content

e definition and the how and why's of it


zedjr
 Share

Recommended Posts

Am trying to find a good explanation of the e. AM guessing it is similar ot that of c sharp. THe forum wont let me do searches for udner 3 letters so am asking if anyone knows where a good explanation of it is. Searched google and got poor results back from it. btw am not looking for the math.e defientiion. Am looking for a definition when it is used liek below. function DisplayKey(e) { // which key was pressed? if (e.keyCode) keycode=e.keyCode; else keycode=e.which; character=String.fromCharCode(keycode); // find the object for the destination paragraph k = document.getElementById("keys"); // add the character to the paragraph k.innerHTML += character; }

Edited by zedjr
Link to comment
Share on other sites

You mean the letter 'e' in something like this:

elem.onclick = function(e) {   ...some code...}

That's just a variable name. It doesn't really mean anything. You could put anything you wanted in there. It's just that most developers seem to prefer the letter 'e'.What's important is the value of e. In standards compliant browsers, e holds a reference to an event. An event holds many useful properties such as mouse coordinates.You can take a look here to learn a little more about events.

Link to comment
Share on other sites

So is e jsut a variable container for teh event passed into the displaykey function?

Link to comment
Share on other sites

ok thanks,, my author alot of times just dont explain things that he newly introduces. I get it.

Link to comment
Share on other sites

well, it would probably be under the chapter explaining functions and how to pass and return values to them. Not sure if the author has gone over that part or not yet.

Link to comment
Share on other sites

For standard compliant browsers, can we also use the word 'event' in the place of 'e' as well?So instead of 'e', is this the same:

function DisplayKey(event) {// which key was pressed?if (event.keyCode) keycode=event.keyCode;else keycode=event.which;character=String.fromCharCode(keycode);// find the object for the destination paragraphk = document.getElementById("keys");// add the character to the paragraphk.innerHTML += character;}

Link to comment
Share on other sites

i think you're missing the point. It doesn't matter what the word is between the parens. That's just how the function sees everything passed to it. you could call it afdsfsdfds and would the same thing. e is just more meaningful. What is usually tested for on the variable passed in is properties, which you can use to determine how to handle the event based on what browser may or may not be executing the function.edit: to combine mine and DD's into one

function DisplayKey(anyNameYouWant) {  something = anyNameYouWant || window.event;};

the point here is to give you a greater understanding of how function call and returns work. as well as in this particular case, how to handle an event. (as typically the convention here is to use e)

Edited by thescientist
Link to comment
Share on other sites

can we also use the word 'event' in the place of 'e' as well?
I don't recommend that, since a complete technique should also test for the global IE event object, and having a global variable share a name with a local variable could get confusing. I'm surprised the original function even looks like that. Mine look more like this:
function DisplayKey(e) {   e = e || window.event;   // etc.

Edited by Deirdre's Dad
Link to comment
Share on other sites

My apologies, I should of gave a better example of what I was trying to ask. I was asking, when passing the event for a particular element to a function, is it passed using the word "event" or can we also use "e" in that instance?For example:

<html><head><script type="text/javascript">function getEventType(e) // Yes I understand we can put anything there for the parameter. { alert(e.type);}</script></head><body onmousedown="getEventType(event)"> <!--Here, to pass the event above, the word 'event' has to be used. I was under the impression that 'e' was allowed here too for the event; just a shorter way instead of the word 'event'--><p>Click in the document.An alert box will tell what type of event that was triggered.</p></body></html>

Link to comment
Share on other sites

<body onmousedown="getEventType(event)">
If you don't use the technique I showed you in Post #10, then you sort of have to do it this way. What you are passing in this case is (1) nothing, if the browser is standards compliant, or (2) window.event, if the browser is an old version of IE.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...