EventDispatcher.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>EventDispatcher - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">EventDispatcher</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>This modules allows to dispatch event objects on custom JavaScript objects.</p>
  16. <p>Main repository: <a href="https://github.com/mrdoob/eventdispatcher.js/" target="_blank" rel="noopener">eventdispatcher.js</a></p>
  17. <p>Code Example:</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">class Car extends EventDispatcher {
  20. start() {
  21. this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
  22. }
  23. };
  24. // Using events with the custom object
  25. const car = new Car();
  26. car.addEventListener( 'start', function ( event ) {
  27. alert( event.message );
  28. } );
  29. car.start();
  30. </code></pre></div>
  31. </header>
  32. <article>
  33. <div class="container-overview">
  34. <h2>Constructor</h2>
  35. <h3 class="name name-method" id="EventDispatcher" translate="no">new <a href="#EventDispatcher">EventDispatcher</a><span class="signature">()</span> </h3>
  36. <div class="method">
  37. </div>
  38. </div>
  39. <h2 class="subsection-title">Methods</h2>
  40. <h3 class="name name-method" id="addEventListener" translate="no">.<a href="#addEventListener">addEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span> </h3>
  41. <div class="method">
  42. <div class="description">
  43. <p>Adds the given event listener to the given event type.</p>
  44. </div>
  45. <table class="params">
  46. <tbody>
  47. <tr>
  48. <td class="name">
  49. <strong>type</strong>
  50. </td>
  51. <td class="description last">
  52. <p>The type of event to listen to.</p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="name">
  57. <strong>listener</strong>
  58. </td>
  59. <td class="description last">
  60. <p>The function that gets called when the event is fired.</p>
  61. </td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. </div>
  66. <h3 class="name name-method" id="dispatchEvent" translate="no">.<a href="#dispatchEvent">dispatchEvent</a><span class="signature">( event : <span class="param-type">Object</span> )</span> </h3>
  67. <div class="method">
  68. <div class="description">
  69. <p>Dispatches an event object.</p>
  70. </div>
  71. <table class="params">
  72. <tbody>
  73. <tr>
  74. <td class="name">
  75. <strong>event</strong>
  76. </td>
  77. <td class="description last">
  78. <p>The event that gets fired.</p>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. <h3 class="name name-method" id="hasEventListener" translate="no">.<a href="#hasEventListener">hasEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span><span class="type-signature"> : boolean</span> </h3>
  85. <div class="method">
  86. <div class="description">
  87. <p>Returns <code>true</code> if the given event listener has been added to the given event type.</p>
  88. </div>
  89. <table class="params">
  90. <tbody>
  91. <tr>
  92. <td class="name">
  93. <strong>type</strong>
  94. </td>
  95. <td class="description last">
  96. <p>The type of event.</p>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td class="name">
  101. <strong>listener</strong>
  102. </td>
  103. <td class="description last">
  104. <p>The listener to check.</p>
  105. </td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. <dl class="details">
  110. <dt class="tag-returns"><strong>Returns:</strong> Whether the given event listener has been added to the given event type.</dt>
  111. </dl>
  112. </div>
  113. <h3 class="name name-method" id="removeEventListener" translate="no">.<a href="#removeEventListener">removeEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span> </h3>
  114. <div class="method">
  115. <div class="description">
  116. <p>Removes the given event listener from the given event type.</p>
  117. </div>
  118. <table class="params">
  119. <tbody>
  120. <tr>
  121. <td class="name">
  122. <strong>type</strong>
  123. </td>
  124. <td class="description last">
  125. <p>The type of event.</p>
  126. </td>
  127. </tr>
  128. <tr>
  129. <td class="name">
  130. <strong>listener</strong>
  131. </td>
  132. <td class="description last">
  133. <p>The listener to remove.</p>
  134. </td>
  135. </tr>
  136. </tbody>
  137. </table>
  138. </div>
  139. <h2 class="subsection-title">Source</h2>
  140. <p>
  141. <a href="https://github.com/mrdoob/three.js/blob/master/src/core/EventDispatcher.js" translate="no" target="_blank" rel="noopener">src/core/EventDispatcher.js</a>
  142. </p>
  143. </article>
  144. </section>
  145. <script src="../scripts/linenumber.js"></script>
  146. <script src="../scripts/page.js"></script>
  147. </body>
  148. </html>
粤ICP备19079148号