EventEmitter

.Events. EventEmitter

事件发射器是一个场景系统插件兼容版本的事件发射器3.

Constructor

new EventEmitter()

Since:
  • 3.0.0

Methods

addListener(event, fn, contextopt) → {this}

Since:
  • 3.0.0
为给定事件添加侦听器.
Parameters:
Name Type Attributes Default Description
event string | symbol 事件名称.
fn function 侦听器函数.
context * <optional>
this 用来调用侦听器的上下文.
Returns:
`this`.
Type
this

destroy()

Since:
  • 3.0.0
移除所有侦听器.

emit(event, …argsopt) → {boolean}

Since:
  • 3.0.0
调用为给定事件注册的每个侦听器.
Parameters:
Name Type Attributes Description
event string | symbol 事件名称.
args * <optional>
<repeatable>
将传递给事件处理程序的附加参数.
Returns:
`true` 如果事件有侦听器,则为 `false` .
Type
boolean

eventNames() → {Array.<(string|symbol)>}

Since:
  • 3.0.0
返回一个数组,列出发射器已注册侦听器的事件.
Returns:
Type
Array.<(string|symbol)>

listenerCount(event) → {number}

Since:
  • 3.0.0
返回监听给定事件的侦听器数量.
Parameters:
Name Type Description
event string | symbol 事件名称.
Returns:
侦听器的数量.
Type
number

listeners(event) → {Array.<function()>}

Since:
  • 3.0.0
返回为给定事件注册的侦听器.
Parameters:
Name Type Description
event string | symbol 事件名称.
Returns:
注册的听众.
Type
Array.<function()>

off(event, fnopt, contextopt, onceopt) → {this}

Since:
  • 3.0.0
移除给定事件的侦听器.
Parameters:
Name Type Attributes Description
event string | symbol 事件名称.
fn function <optional>
仅移除与此函数匹配的侦听器.
context * <optional>
仅移除具有此上下文的侦听器.
once boolean <optional>
仅删除一次性侦听器.
Returns:
`this`.
Type
this

on(event, fn, contextopt) → {this}

Since:
  • 3.0.0
为给定事件添加侦听器.
Parameters:
Name Type Attributes Default Description
event string | symbol 事件名称.
fn function 侦听器函数.
context * <optional>
this 用来调用侦听器的上下文.
Returns:
`this`.
Type
this

once(event, fn, contextopt) → {this}

Since:
  • 3.0.0
为给定事件添加一次性侦听器.
Parameters:
Name Type Attributes Default Description
event string | symbol 事件名称.
fn function 侦听器函数.
context * <optional>
this 用来调用侦听器的上下文.
Returns:
`this`.
Type
this

removeAllListeners(eventopt) → {this}

Since:
  • 3.0.0
移除所有侦听器或指定事件的侦听器.
Parameters:
Name Type Attributes Description
event string | symbol <optional>
事件名称.
Returns:
`this`.
Type
this

removeListener(event, fnopt, contextopt, onceopt) → {this}

Since:
  • 3.0.0
移除给定事件的侦听器.
Parameters:
Name Type Attributes Description
event string | symbol 事件名称.
fn function <optional>
仅移除与此函数匹配的侦听器.
context * <optional>
仅移除具有此上下文的侦听器.
once boolean <optional>
仅删除一次性侦听器.
Returns:
`this`.
Type
this

shutdown()

Since:
  • 3.0.0
移除所有侦听器.