用于管理特定事件的订阅者的通用实用程序类。此类通常在容器类内部实例化,并作为属性公开以供其他人订阅。 A generic utility class for managing subscribers for a particular event. This class is usually instantiated inside of a container class and exposed as a property for others to subscribe to.
示例: Example:
MyObject.prototype.myListener = function(arg1, arg2) {
this.myArg1Copy = arg1;
this.myArg2Copy = arg2;
}
const myObjectInstance = new MyObject();
const evt = new Cesium.Event();
evt.addEventListener(MyObject.prototype.myListener, myObjectInstance);
evt.raiseEvent('1', '2');
evt.removeEventListener(MyObject.prototype.myListener);
成员 Members
当前订阅该事件的侦听器数量。 The number of listeners currently subscribed to the event.
方法 Methods
addEventListener(listener, scope) → Event.RemoveCallback
注册一个回调函数,在事件发生时执行。可以提供一个可选范围作为 Registers a callback function to be executed whenever the event is raised. An optional scope can be provided to serve as the
this 函数将在其中执行的指针。 pointer in which the function will execute.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
listener |
Listener | 引发事件时要执行的函数。 The function to be executed when the event is raised. |
scope |
object |
可选 optional
一个可选的对象范围作为 An optional object scope to serve as the this
将在其中执行侦听器函数的指针。 pointer in which the listener function will execute. |
返回: Returns:
调用时将删除此事件侦听器的函数。 A function that will remove this event listener when invoked.
通过使用所有提供的参数调用每个注册的侦听器来引发事件。 Raises the event by calling each registered listener with all supplied arguments.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
arguments |
Parameters.<Listener> | 可重复 repeatable 此方法接受任意数量的参数并将它们传递给侦听器函数。 This method takes any number of parameters and passes them through to the listener functions. |
取消注册先前注册的回调。 Unregisters a previously registered callback.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
listener |
Listener | 要取消注册的函数。 The function to be unregistered. |
scope |
object | 可选 optional 最初传递给 addEventListener 的范围。 The scope that was originally passed to addEventListener. |
返回: Returns:
true 如果监听器被移除; if the listener was removed; false 如果侦听器和作用域未向事件注册。 if the listener and scope are not registered with the event.
另见: See:
类型定义 Type Definitions
删除侦听器的函数。 A function that removes a listener.
