gs-events
Version:
727 lines (466 loc) • 35 kB
HTML
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../">
<title data-ice="title">EventDispatcher | gs-events</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
<script src="script/manual.js"></script>
<meta name="description" content="事件分发器(同步)"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="gs-events"><meta property="twitter:description" content="事件分发器(同步)"></head>
<body class="layout-container" data-ice="rootContainer">
<header>
<a href="./">Home</a>
<a href="identifiers.html">Reference</a>
<a href="source.html">Source</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
<a style="position:relative; top:3px;" href="https://github.com/guless/events"><img width="20px" src="./image/github.png"></a></header>
<nav class="navigation" data-ice="nav"><div>
<ul>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/CustomEvent.js~CustomEvent.html">CustomEvent</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/Event.js~Event.html">Event</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html">EventDispatcher</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventListener.js~EventListener.html">EventListener</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventListenerOptions.js~EventListenerOptions.html">EventListenerOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventPhase.js~EventPhase.html">EventPhase</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><div class="header-notice">
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import EventDispatcher from '<span><a href="file/src/EventDispatcher.js.html#lineNumber50">gs-events/src/EventDispatcher.js</a></span>'</code></pre></div>
<span data-ice="access">public</span>
<span data-ice="kind">class</span>
<span data-ice="since">| since 1.0.0</span>
<span data-ice="source">| <span><a href="file/src/EventDispatcher.js.html#lineNumber50">source</a></span></span>
</div>
<div class="self-detail detail">
<h1 data-ice="name">EventDispatcher</h1>
<div class="flat-list" data-ice="implements"><h4>Implements:</h4><ul><li><span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span></li></ul></div>
<div class="description" data-ice="description"><p>定义所有具备事件派发功能对象的基类。</p>
</div>
</div>
<div data-ice="constructorSummary"><h2>Constructor Summary</h2><table class="summary" data-ice="summary">
<thead><tr><td data-ice="title" colspan="3">Public Constructor</td></tr></thead>
<tbody>
<tr data-ice="target">
<td>
<span class="access" data-ice="access">public</span>
<span class="override" data-ice="override"></span>
</td>
<td>
<div>
<p>
<span class="code" data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html#instance-constructor-constructor">constructor</a></span></span><span class="code" data-ice="signature">(target: <span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span>)</span>
</p>
</div>
<div>
<div data-ice="description"><p>创建一个事件派发器。</p>
</div>
</div>
</td>
<td>
<span class="since" data-ice="since">since 1.0.0</span>
</td>
</tr>
</tbody>
</table>
</div>
<div data-ice="methodSummary"><h2>Method Summary</h2><table class="summary" data-ice="summary">
<thead><tr><td data-ice="title" colspan="3">Public Methods</td></tr></thead>
<tbody>
<tr data-ice="target">
<td>
<span class="access" data-ice="access">public</span>
<span class="override" data-ice="override"></span>
</td>
<td>
<div>
<p>
<span class="code" data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html#instance-method-addEventListener">addEventListener</a></span></span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>, handler: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span>, options: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span>)</span>
</p>
</div>
<div>
<div data-ice="description"><p>注册一个事件侦听器。</p>
</div>
</div>
</td>
<td>
<span class="since" data-ice="since">since 1.0.0</span>
</td>
</tr>
<tr data-ice="target">
<td>
<span class="access" data-ice="access">public</span>
<span class="override" data-ice="override"></span>
</td>
<td>
<div>
<p>
<span class="code" data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html#instance-method-dispatchEvent">dispatchEvent</a></span></span><span class="code" data-ice="signature">(event: <span><a href="class/src/Event.js~Event.html">Event</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></span>
</p>
</div>
<div>
<div data-ice="description"><p>派发一个事件对象到目标对象的事件流中。</p>
</div>
</div>
</td>
<td>
<span class="since" data-ice="since">since 1.0.0</span>
</td>
</tr>
<tr data-ice="target">
<td>
<span class="access" data-ice="access">public</span>
<span class="override" data-ice="override"></span>
</td>
<td>
<div>
<p>
<span class="code" data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html#instance-method-hasEventListener">hasEventListener</a></span></span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></span>
</p>
</div>
<div>
<div data-ice="description"><p>检查是否注册了指定类型的事件侦听器。</p>
</div>
</div>
</td>
<td>
<span class="since" data-ice="since">since 1.0.0</span>
</td>
</tr>
<tr data-ice="target">
<td>
<span class="access" data-ice="access">public</span>
<span class="override" data-ice="override"></span>
</td>
<td>
<div>
<p>
<span class="code" data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html#instance-method-removeEventListener">removeEventListener</a></span></span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>, handler: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span>, useCapture: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span>)</span>
</p>
</div>
<div>
<div data-ice="description"><p>移除一个事件侦听器。</p>
</div>
</div>
</td>
<td>
<span class="since" data-ice="since">since 1.0.0</span>
</td>
</tr>
</tbody>
</table>
</div>
<div data-ice="constructorDetails"><h2 data-ice="title">Public Constructors</h2>
<div class="detail" data-ice="detail">
<h3 data-ice="anchor" id="instance-constructor-constructor">
<span class="access" data-ice="access">public</span>
<span class="code" data-ice="name">constructor</span><span class="code" data-ice="signature">(target: <span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span>)</span>
<span class="right-info">
<span class="since" data-ice="since">since 1.0.0</span>
<span data-ice="source"><span><a href="file/src/EventDispatcher.js.html#lineNumber56">source</a></span></span>
</span>
</h3>
<div data-ice="description"><p>创建一个事件派发器。</p>
</div>
<div data-ice="properties"><div data-ice="properties">
<h4 data-ice="title">Params:</h4>
<table class="params">
<thead>
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
</thead>
<tbody>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">target</td>
<td data-ice="type" class="code"><span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span></td>
<td data-ice="appendix"><ul><li>optional</li>
<li>default: null</li></ul></td>
<td data-ice="description"><p>指定派发器的代理目标对象。</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div data-ice="methodDetails"><h2 data-ice="title">Public Methods</h2>
<div class="detail" data-ice="detail">
<h3 data-ice="anchor" id="instance-method-addEventListener">
<span class="access" data-ice="access">public</span>
<span class="code" data-ice="name">addEventListener</span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>, handler: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span>, options: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span>)</span>
<span class="right-info">
<span class="since" data-ice="since">since 1.0.0</span>
<span data-ice="source"><span><a href="file/src/EventDispatcher.js.html#lineNumber140">source</a></span></span>
</span>
</h3>
<div data-ice="description"><p>注册一个事件侦听器。</p>
<p>如果浏览器支持 <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span> 类型,则事件类型可以使用 <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span> 对象,这样可以防止
你的事件被其他人意外的移除。</p>
<p>事件侦听器可以注册到派发事件的任何一个阶段,<strong>捕获阶段</strong>和<strong>冒泡阶段</strong>的侦听器是相互独立的。
因此使用不同的 <code>useCapture</code> 值将注册不同的侦听器。同样移除的时候,也需要指定不同的 <code>useCapture</code> 值。 </p>
<p>事件处理函数默认的作用域为派发器(<code>EventDispatcher</code>)对象或者其代理的对象,通过设置 <code>options.scope</code>
可以为事件处理函数指定作用域。但是如果注册的是一个实现了 <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span> 接口的对象,则直接
调用其 <code>handleEvent()</code> 方法处理事件,并且作用域始终指向该 <code>IEventListener</code> 对象。</p>
<p>通过指定 <code>options.once</code> 选项,可以指定侦听器在执行后,是否自动从列表中移除。</p>
<p>优先级高(<code>options.priority</code>)的侦听器会在派发事件时优先调用。相同优先级的情况会按照注册的先后
顺序调用侦听器。分别使用不同的优先级注册相同的侦听器时,以最后一次注册的侦听器为准。</p>
</div>
<div data-ice="properties"><div data-ice="properties">
<h4 data-ice="title">Params:</h4>
<table class="params">
<thead>
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
</thead>
<tbody>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">type</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>事件类型。</p>
</td>
</tr>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">handler</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>指定事件处理函数或者是一个事件侦听器。</p>
</td>
</tr>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">options</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span></td>
<td data-ice="appendix"><ul><li>optional</li>
<li>default: false</li></ul></td>
<td data-ice="description"><p>指定侦听器配置选项。</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-ice="example">
<h4>Example:</h4>
<div class="example-doc" data-ice="exampleDoc">
<pre class="prettyprint source-code"><code data-ice="exampleCode">const dispatcher = new EventDispatcher();
/// 在冒泡阶段注册侦听器。
dispatcher.addEventListener("custom", ( evt ) => {});
dispatcher.addEventListener("custom", ( evt ) => {}, false);
/// 在捕获阶段注册侦听器。
dispatcher.addEventListener("custom", ( evt ) => {}, true);
/// 指定事件处理函数的作用域。
const target = {};
dispatcher.addEventListener("custom", ( evt ) => {
console.log(target === this); // true
}, { "scope": target });
/// 注册一次性的侦听器。
dispatcher.addEventListener("custom", ( evt ) => {
/// 该函数执行后,将自动从列表中移除。
}, { "once": true });
/// 尽管该侦听器后注册的,但是因为具有较高的优先级,所以会先被调用。
dispatcher.addEventListener("custom", ( evt ) => {
console.log(1);
}, { "priority": 1 });
/// 相同的侦听器使用不用的优先级多次注册,以最后一次注册的优先级为准。
const handler = ( evt ) => {};
dispatcher.addEventListener("custom", handler, { "priority": 1 });
dispatcher.addEventListener("custom", handler, { "priority": 2 }); // 只会注册一个优先级为 2 的侦听器。</code></pre>
</div>
</div>
<div data-ice="see"><h4>See:</h4><ul><li><span><span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span></span></li></ul></div>
</div>
<div class="detail" data-ice="detail">
<h3 data-ice="anchor" id="instance-method-dispatchEvent">
<span class="access" data-ice="access">public</span>
<span class="code" data-ice="name">dispatchEvent</span><span class="code" data-ice="signature">(event: <span><a href="class/src/Event.js~Event.html">Event</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></span>
<span class="right-info">
<span class="since" data-ice="since">since 1.0.0</span>
<span data-ice="source"><span><a href="file/src/EventDispatcher.js.html#lineNumber286">source</a></span></span>
</span>
</h3>
<div data-ice="description"><p>派发一个事件对象到目标对象的事件流中。</p>
</div>
<div data-ice="properties"><div data-ice="properties">
<h4 data-ice="title">Params:</h4>
<table class="params">
<thead>
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
</thead>
<tbody>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">event</td>
<td data-ice="type" class="code"><span><a href="class/src/Event.js~Event.html">Event</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>指定派发的事件对象。</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="return-params" data-ice="returnParams">
<h4>Return:</h4>
<table>
<tbody>
<tr>
<td class="return-type code" data-ice="returnType"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></td>
<td class="return-desc" data-ice="returnDescription"><p>如果事件传递到了当前目标对象,并且没有被取消默认行为。则返回 <code>true</code>,否则返回 <code>false</code>。</p>
</td>
</tr>
</tbody>
</table>
<div data-ice="returnProperties">
</div>
</div>
<div data-ice="example">
<h4>Example:</h4>
<div class="example-doc" data-ice="exampleDoc">
<pre class="prettyprint source-code"><code data-ice="exampleCode">const dispatcher = new EventDispatcher();
dispatcher.dispatchEvent(new Event("custom", false, false)); // 派发一个不冒泡的事件。
dispatcher.dispatchEvent(new Event("custom", true, false)); // 派发一个参与冒泡的事件。</code></pre>
</div>
</div>
</div>
<div class="detail" data-ice="detail">
<h3 data-ice="anchor" id="instance-method-hasEventListener">
<span class="access" data-ice="access">public</span>
<span class="code" data-ice="name">hasEventListener</span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></span>
<span class="right-info">
<span class="since" data-ice="since">since 1.0.0</span>
<span data-ice="source"><span><a href="file/src/EventDispatcher.js.html#lineNumber271">source</a></span></span>
</span>
</h3>
<div data-ice="description"><p>检查是否注册了指定类型的事件侦听器。</p>
</div>
<div data-ice="properties"><div data-ice="properties">
<h4 data-ice="title">Params:</h4>
<table class="params">
<thead>
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
</thead>
<tbody>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">type</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>事件类型。</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="return-params" data-ice="returnParams">
<h4>Return:</h4>
<table>
<tbody>
<tr>
<td class="return-type code" data-ice="returnType"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span></td>
<td class="return-desc" data-ice="returnDescription"><p>如果存在指定类型的侦听器则返回 <code>true</code>,否则返回 <code>false</code>。</p>
</td>
</tr>
</tbody>
</table>
<div data-ice="returnProperties">
</div>
</div>
<div data-ice="example">
<h4>Example:</h4>
<div class="example-doc" data-ice="exampleDoc">
<pre class="prettyprint source-code"><code data-ice="exampleCode">const dispatcher = new EventDispatcher();
dispatcher.addEventListener("custom", ( evt ) => {}, false);
console.log(dispatcher.hasEventListener("custom")); // true
console.log(dispatcher.hasEventListener("notexists")); // false</code></pre>
</div>
</div>
</div>
<div class="detail" data-ice="detail">
<h3 data-ice="anchor" id="instance-method-removeEventListener">
<span class="access" data-ice="access">public</span>
<span class="code" data-ice="name">removeEventListener</span><span class="code" data-ice="signature">(type: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span>, handler: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span>, useCapture: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span>)</span>
<span class="right-info">
<span class="since" data-ice="since">since 1.0.0</span>
<span data-ice="source"><span><a href="file/src/EventDispatcher.js.html#lineNumber225">source</a></span></span>
</span>
</h3>
<div data-ice="description"><p>移除一个事件侦听器。</p>
<p>第三个参数 <code>useCapture</code> 可以是一个 <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> 类型的值,或者是一个 <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span> 类型的值。</p>
<p>只有完全相同(使用 === 对比)的侦听器才会被移除。因此使用 <code>useCapture=false</code> 并不会移除<strong>捕获阶段</strong>的侦听器。
同理 <code>useCapture=true</code> 也不会移除<strong>冒泡阶段</strong>的侦听器。</p>
</div>
<div data-ice="properties"><div data-ice="properties">
<h4 data-ice="title">Params:</h4>
<table class="params">
<thead>
<tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr>
</thead>
<tbody>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">type</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></span> | <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>事件类型。</p>
</td>
</tr>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">handler</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></span> | <span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span></td>
<td data-ice="appendix"></td>
<td data-ice="description"><p>指定要移除的事件处理函数或者事件侦听器。</p>
</td>
</tr>
<tr data-ice="property" data-depth="0">
<td data-ice="name" class="code" data-depth="0">useCapture</td>
<td data-ice="type" class="code"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></span> | <span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span></td>
<td data-ice="appendix"><ul><li>optional</li>
<li>default: false</li></ul></td>
<td data-ice="description"><p>指定是移除捕获阶段(<code>true</code>)还是冒泡阶段(<code>false</code>)的事件侦听器。</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-ice="example">
<h4>Example:</h4>
<div class="example-doc" data-ice="exampleDoc">
<pre class="prettyprint source-code"><code data-ice="exampleCode">/// 使用不用类型的 useCapture 值移除侦听器。
dispatcher.removeEventListener(type, handler, false);
dispatcher.removeEventListener(type, handler, { "useCapture": true });
/// 分别移除不用阶段的侦听器。
const dispatcher = new EventDispatcher();
function captureHandler( evt ) {
console.log("capture");
}
dispatcher.addEventListener("custom", captureHandler, true);
dispatcher.removeEventListener("custom", captureHandler, false); // 这里并不会移除 captureHandler 侦听器。
dispatcher.hasEventListener("custom"); // true
dispatcher.removeEventListener("custom", captureHandler, true); // 这里才会移除 captureHandler 侦听器。
dispatcher.hasEventListener("custom"); // false</code></pre>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>