EventDispatcher.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="../../list.js"></script>
  6. <script src="../../page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="../../page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <div class="desc">JavaScript events for custom objects</div>
  12. <h2>Example</h2>
  13. <code>
  14. var Car = function () {
  15. EventDispatcher.call( this );
  16. this.start = function () {
  17. this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
  18. };
  19. };
  20. var car = new Car();
  21. car.addEventListener( 'start', function ( event ) { alert( event.message ); } );
  22. car.start();
  23. </code>
  24. <h2>Constructor</h2>
  25. <h3>[name]()</h3>
  26. <div>
  27. Creates eventDispatcher object. It needs to be call with '.call' to add the functionality to an object.
  28. </div>
  29. <h2>Methods</h2>
  30. <h3>.addEventListener( [page:String type], [page:Function listener] </h3>
  31. <div>
  32. type - The type of event to listen to.<br />
  33. listener - The function that gets called when the event is fired.
  34. </div>
  35. <div>
  36. Adds a listener to an event type.
  37. </div>
  38. <h3>.removeEventListener( [page:String type], [page:Function listener] </h3>
  39. <div>
  40. type - The type of the listener that gets removed.<br />
  41. listener - The listener function that gets removed.
  42. </div>
  43. <div>
  44. Removes a listener from an event type.
  45. </div>
  46. <h3>.dispatchEvent( [page:String type]</h3>
  47. <div>
  48. type - The type of event that gets fired.
  49. </div>
  50. <div>
  51. Fire an event type.
  52. </div>
  53. <h2>Source</h2>
  54. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  55. </body>
  56. </html>