Skip to content

KBE3D / KBCore / Cesium / Event

类: Event<Listener>

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.

示例

ts
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);

类型参数

Listener

Listener extends (...args: any[]) => void = (...args: any[]) => void

属性

numberOfListeners

readonly numberOfListeners: number

The number of listeners currently subscribed to the event.

方法

addEventListener()

addEventListener(listener: Listener, scope?: any): RemoveCallback

Registers a callback function to be executed whenever the event is raised. An optional scope can be provided to serve as the <code>this</code> pointer in which the function will execute.

参数

listener

Listener

The function to be executed when the event is raised.

scope?

any

An optional object scope to serve as the <code>this</code> pointer in which the listener function will execute.

返回

RemoveCallback

A function that will remove this event listener when invoked.


removeEventListener()

removeEventListener(listener: Listener, scope?: any): boolean

Unregisters a previously registered callback.

参数

listener

Listener

The function to be unregistered.

scope?

any

The scope that was originally passed to addEventListener.

返回

boolean

true if the listener was removed; false if the listener and scope are not registered with the event.


raiseEvent()

raiseEvent(...arguments: Parameters<Listener>): void

Raises the event by calling each registered listener with all supplied arguments.

参数

arguments

...Parameters<Listener>

This method takes any number of parameters and passes them through to the listener functions.

返回

void

构造函数

构造函数

new Event<Listener>(): Event<Listener>

返回

Event<Listener>

KBE3D @3.0.0 Copyright © 2024-present KBE3D