Hi all,

I'm only new to Javascript so not sure the propper/best way of writing code, but have managed to build a working Custom Event Handling class!

Just positing this in the boards to see if anyone else has any suggestions/ or better way which I have overlooked.

I also plan on extending it to work with the normal events (onClick, onLoad) etc as well.

Thanks

Code JavaScript:
var Event = 
{
	//add an event chain
	addChain: function( pObj, pName )
	{
		pObj['_event' + pName ] = Array();
	},
 
 	//add an event to the end of the chain
 addEvent: function( pObj, pName, pRet , pFunc , pParams)
 {
	 pObj['_event' + pName ].push( [ pRet , pFunc, pParams ]);
 
 },
 
 	//removes the chain
 removeChain: function( pObj, pName )
 {
	 this.throwEvent( pObj, '_removeChain');
	 delete pObj['_event' + pName ];
 },
 
  	//removes all events
 clearEvents: function ( pObj, pName)
 {
	 this.throwEvent( pObj, '_removeEvent');
	 this.addEvent(pObj, pname);
 },
 
 	//throw an event
 throwEvent: function( pObj, pName)
 {
	 for (var tEvt in pObj['_event' + pName ])
	 {
		 var tE = pObj['_event' + pName ][tEvt];
 
		 tA = tE[2];
		 tA.push( [ pObj, pName ]);
 
			/*var tA = Array();
		 tA.push( [ pObj, pName]);
		 for(var tArgs in tE[2])
		 {
		 tA.push( tE[2][tArgs] ); 
	 }*/
 
		 tE[1].apply( tE[0], tA);
	 }
 },
 
};

example of use
Code JavaScript:
Car = new function()  
{
	Event.addChain(this, "StartEngine");
	Event.addChain(this, "ChangeGearUp");
	Event.addChain(this, "ChangeGearDown");
	this.gear = 1;
 
	this.startEngine = function ( )
	{
		Event.throwEvent(this, "StartEngine");
	}
}
 
Race = new function()
{
 
	this.raceStarted = false;
	this.car_engine_started = function ( evt )
	{
		if( this.raceStarted == false)
			alert("Car has started their engine brefore the race has started"); 
	}
 
	this.startRace = function()
	{
		this.raceStarted = true;
	}
	Event.addEvent( Car, "StartEngine", this, this.car_engine_started, [] );
}
 
Car.startEngine();
Race.startRace();