JavaScript events for custom objects
Switch branches/tags
Nothing to show
Clone or download
Latest commit 42eee11 Jun 10, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Improved example. Jun 9, 2017
src Upstreaming from three.js. Jun 9, 2017
LICENSE Added description and usage example to README Oct 27, 2011
README.md Updated README.md Jun 9, 2017
bower.json fix author and homepage fields in bower package May 4, 2016

README.md

eventdispatcher.js

JavaScript events for custom objects

Usage

<script src="EventDispatcher.js"></script>
<script>

	// Adding events to custom object

	function Car() {

		this.start = function () {

			this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );

		};

	}

	Object.assign( Car.prototype, EventDispatcher.prototype );

	// Using events

	var car = new Car();

	car.addEventListener( 'start', function ( event ) {

		alert( event.message );

	} );

	car.start();

</script>