zedjr Posted August 11, 2011 Share Posted August 11, 2011 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; } Link to comment Share on other sites More sharing options...
ShadowMage Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
Drycodez Posted August 11, 2011 Share Posted August 11, 2011 It is just a data passed into the function. E.g: function popup(e){alert(e)}//call the function popup("hello world!") Link to comment Share on other sites More sharing options...
zedjr Posted August 11, 2011 Author Share Posted August 11, 2011 So is e jsut a variable container for teh event passed into the displaykey function? Link to comment Share on other sites More sharing options...
thescientist Posted August 11, 2011 Share Posted August 11, 2011 yes.edit: it's not really a container, it's just variable. Link to comment Share on other sites More sharing options...
zedjr Posted August 11, 2011 Author Share Posted August 11, 2011 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 More sharing options...
thescientist Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
Don E Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
thescientist Posted August 12, 2011 Share Posted August 12, 2011 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) Link to comment Share on other sites More sharing options...
jeffman Posted August 12, 2011 Share Posted August 12, 2011 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. Link to comment Share on other sites More sharing options...
Don E Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
justsomeguy Posted August 12, 2011 Share Posted August 12, 2011 You don't need to manually pass the event, the browser will do that automatically. Link to comment Share on other sites More sharing options...
thescientist Posted August 12, 2011 Share Posted August 12, 2011 nm. Link to comment Share on other sites More sharing options...
jeffman Posted August 12, 2011 Share Posted August 12, 2011 <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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.