Class: Target

events~ Target


new Target()

Methods


dispatchEvent(event)

发送事件消息,每个事件消息都有类型(type),所有监听此对象对应类型事件的监听者都会接收到相应的事件消息
Parameters:
Name Type Description
event string | module:events.Event 事件对象

destroy()

销毁对象并移除当前对象所有的监听器

on(type, listener [, opt_this])

指定监听器监听指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身
Returns:
监听器的唯一标识.
Type
Object

once(type, listener [, opt_this])

指定监听器只监听一次指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身
Returns:
监听器的唯一标识.
Type
Object

un(type, listener [, opt_this])

取消指定监听器监听指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身

unByKey(key)

根据监听器的唯一标识取消指定监听器监听事件,监听器的唯一标识通过`on()`或者`once()`返回得到
Parameters:
Name Type Description
key Object | Array.<Object> 监听器的唯一标识,通过`on()`或者`once()`返回得到,可以是多个监听器的唯一标识数组