Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IEventified

实现该接口的对象具有处理事件的能力。

Hierarchy

  • IEventified

Index

Methods

emit

  • emit(type: EventType, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
  • 派发一个指定事件,并传递需要的参数

    Parameters

    • type: EventType

      event type

    • Optional arg0: any
    • Optional arg1: any
    • Optional arg2: any
    • Optional arg3: any
    • Optional arg4: any

    Returns void

hasEventListener

  • hasEventListener(type: string, callback?: Function, target?: undefined | object): boolean
  • 检查指定事件是否已注册回调。

    Parameters

    • type: string

      Event type.

    • Optional callback: Function

      Callback function when event triggered.

    • Optional target: undefined | object

      Callback callee.

    Returns boolean

off

  • 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。

    example

    import { log } from 'cc'; // register fire eventListener var callback = eventTarget.on('fire', function () { log("fire in the hole"); }, target); // remove fire event listener eventTarget.off('fire', callback, target); // remove all fire event listeners eventTarget.off('fire');

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type being removed.

    • Optional callback: TFunction

      The callback to remove.

    • Optional thisArg: any

    Returns void

on

  • on<TFunction>(type: EventType, callback: TFunction, thisArg?: any, once?: undefined | false | true): typeof callback
  • 注册事件目标的特定事件类型回调。这种类型的事件应该被 emit 触发。

    example

    import { log } from 'cc'; eventTarget.on('fire', function () { log("fire in the hole"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

      The target (this object) to invoke the callback, can be null

    • Optional once: undefined | false | true

    Returns typeof callback

    • Just returns the incoming callback so you can save the anonymous function easier.

once

  • once<TFunction>(type: EventType, callback: TFunction, thisArg?: any): typeof callback
  • 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。

    example

    import { log } from 'cc'; eventTarget.once('fire', function () { log("this is the callback and will be invoked only once"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

    Returns typeof callback

removeAll

  • removeAll(typeOrTarget: string | object): void
  • 移除在特定事件类型中注册的所有回调或在某个目标中注册的所有回调。

    Parameters

    • typeOrTarget: string | object

      The event type or target with which the listeners will be removed

    Returns void

targetOff

  • targetOff(typeOrTarget: string | object): void
  • 在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。 这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。 这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。

    Parameters

    • typeOrTarget: string | object

      The target to be searched for all related listeners

    Returns void

Generated using TypeDoc