You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					98 lines
				
				2.0 KiB
			
		
		
			
		
	
	
					98 lines
				
				2.0 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<!DOCTYPE html>
							 | 
						||
| 
								 | 
							
								<html lang="en">
							 | 
						||
| 
								 | 
							
									<head>
							 | 
						||
| 
								 | 
							
										<meta charset="utf-8" />
							 | 
						||
| 
								 | 
							
										<base href="../../../" />
							 | 
						||
| 
								 | 
							
										<script src="page.js"></script>
							 | 
						||
| 
								 | 
							
										<link type="text/css" rel="stylesheet" href="page.css" />
							 | 
						||
| 
								 | 
							
									</head>
							 | 
						||
| 
								 | 
							
									<body>
							 | 
						||
| 
								 | 
							
										<h1>[name]</h1>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<p class="desc">
							 | 
						||
| 
								 | 
							
											JavaScript events for custom objects.<br />
							 | 
						||
| 
								 | 
							
											[link:https://github.com/mrdoob/eventdispatcher.js EventDispatcher on GitHub]
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>Code Example</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<code>
							 | 
						||
| 
								 | 
							
										// Adding events to a custom object
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										class Car extends EventDispatcher {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											start() {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
												this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// Using events with the custom object
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										const car = new Car();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										car.addEventListener( 'start', function ( event ) {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											alert( event.message );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										} );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										car.start();
							 | 
						||
| 
								 | 
							
										</code>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>Constructor</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[name]()</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										Creates EventDispatcher object.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>Methods</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[method:undefined addEventListener]( [param:String type], [param:Function listener] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										type - The type of event to listen to.<br />
							 | 
						||
| 
								 | 
							
										listener - The function that gets called when the event is fired.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										Adds a listener to an event type.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										type - The type of event to listen to.<br />
							 | 
						||
| 
								 | 
							
										listener - The function that gets called when the event is fired.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										Checks if listener is added to an event type.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[method:undefined removeEventListener]( [param:String type], [param:Function listener] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										type - The type of the listener that gets removed.<br />
							 | 
						||
| 
								 | 
							
										listener - The listener function that gets removed.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										Removes a listener from an event type.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[method:undefined dispatchEvent]( [param:Object event] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										event - The event that gets fired.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										Fire an event type.
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>Source</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
											[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
									</body>
							 | 
						||
| 
								 | 
							
								</html>
							 |