Jump to content

e stand for...


kurt.santo

Recommended Posts

In my quest to understand JavaScript I am coming across the letter "e" a lot in my example codes. Kind of lost in what "e" stands for. Commented the areas of code to mark where the "e-problem" :) occurs. Also entered my assumptions and would welcome anyone having a look to see how bad I am doing;-)

	getKey:function(e){		//checks if window's event method  is supported		if(window.event){			//stores keyCode in var key if window.event is supported	      var key = window.event.keyCode;		  // then I get lost: what is the "e" staning for???	    } else if(e){	      var key=e.keyCode;	    }		return key;	}getTarget:function(e){		/*  the result of the following is stored in the variable target: if window.event is supported it stores the scrElement, otherwise it uses "e" (again, what does e stand for?) to test further. If "e" is true, it stores e.target otherwise, it stores null. Really lost on this one...*/		var target = window.event ? window.event.srcElement : e ? e.target : null;		//if target is not specified, return false		if (!target){return false;}		/*otherwise as long as node Type is not 1 (not an element as <body> for example) and nodeName is not "body" go one up to parent node*/		while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body'){			target=target.parentNode;		}		//then return target		return target;	}		cancelClick:function(e){		if (window.event){			window.event.cancelBubble = true;			window.event.returnValue = false;		}		// again the "e"????		if (e && e.stopPropagation && e.preventDefault){			e.stopPropagation();			e.preventDefault();		}

KurtThe one who is getting there slowly...

Link to comment
Share on other sites

The e variable is an event object. It doesn't matter that it's called e, that's just what it's named in every function:getKey:function(e)getTarget:function(e)cancelClick:function(e)Those functions are set up to be event handlers, they get executed when a particular event gets triggered. Information about the event is stored in an event object and sent to the event handler. The confusion with checking window.event is because browsers use different ways to record the event, some send an event object and some save it in window.event.http://www.howtocreate.co.uk/tutorials/javascript/domevents

Link to comment
Share on other sites

The e variable is an event object. It doesn't matter that it's called e, that's just what it's named in every function:getKey:function(e)getTarget:function(e)cancelClick:function(e)Those functions are set up to be event handlers, they get executed when a particular event gets triggered. Information about the event is stored in an event object and sent to the event handler. The confusion with checking window.event is because browsers use different ways to record the event, some send an event object and some save it in window.event.http://www.howtocreate.co.uk/tutorials/javascript/domevents
Cheers (for advice and website:-))....Kurt
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...