Home Reference Source
import EventListenerOptions from 'gs-events/src/EventListenerOptions.js'
public class | since 1.0.0 | source

EventListenerOptions

定义侦听器配置选项。

See:

Constructor Summary

Public Constructor
public

constructor(scope: IEventDispatcher, once: Boolean, useCapture: Boolean, priority: Number)

创建一个侦听器选项对象。

since 1.0.0

Member Summary

Public Members
public get

指示侦听器是否在执行后,自动从派发器中移除。

since 1.0.0
public get

指示侦听器在派发事件时的优先级。

since 1.0.0
public get

获取侦听器的作用域对象。

since 1.0.0
public get

指示侦听器是否在捕获阶段处理事件。

since 1.0.0

Method Summary

Public Methods
public

使用自定义的参数,初始化当前配置选项。

since 1.0.0

Public Constructors

public constructor(scope: IEventDispatcher, once: Boolean, useCapture: Boolean, priority: Number) since 1.0.0 source

创建一个侦听器选项对象。

Params:

NameTypeAttributeDescription
scope IEventDispatcher
  • optional
  • default: null

指定侦听器的作用域对象。

once Boolean
  • optional
  • default: false

指示侦听器是否在执行后,自动从派发器中移除。

useCapture Boolean
  • optional
  • default: false

指示侦听器是否在捕获阶段处理事件。

priority Number
  • optional
  • default: 0

指示侦听器在派发事件时的优先级(事件派发时会优先执行高优先级的侦听器)。

Public Members

public get once: Boolean since 1.0.0 source

指示侦听器是否在执行后,自动从派发器中移除。

public get priority: Number since 1.0.0 source

指示侦听器在派发事件时的优先级。

public get scope: IEventDispatcher since 1.0.0 source

获取侦听器的作用域对象。

public get useCapture: Boolean since 1.0.0 source

指示侦听器是否在捕获阶段处理事件。

Public Methods

public initWithParams(options: Boolean | IEventListenerOptions): this since 1.0.0 source

使用自定义的参数,初始化当前配置选项。

  • 如果 options 是一个 Boolean 类型的值,则将 options 视为 EventListenerOptions#useCapture
  • 如果 options 是一个 IEventListenerOptions 类型的值,则拷贝 options 的值到当前配置选项中。

Params:

NameTypeAttributeDescription
options Boolean | IEventListenerOptions
  • optional
  • default: false

指定侦听器的配置选项。

Return:

this

Example:

const dispatcher = new EventDispatcher();
const options = new EventListenerOptions();
options.initWithParams({ "once": true, "scope": this });

dispatcher.addEventListener("custom", ( evt ) => {
    /// 该事件侦听器在执行后,会自动从 `dispatcher` 派发器中移除。
    console.log("success");
}, options);

dispatcher.dispatchEvent(new Event("custom", false, false));