Skip to content

Class: EventTarget

事件对象, 可以监听和分发事件

Hierarchy

Table of contents

Constructors

Methods

Constructors

constructor

new EventTarget()

Methods

addEventListener

addEventListener(type, callback): void

增加事件监听

Parameters

NameTypeDescription
typestring事件类型
callbackFunction

Returns

void


dispatchEvent

dispatchEvent(event): void

分发事件

Parameters

NameType
eventany

Returns

void


hasListener

hasListener(type): boolean

是否有该类型的监听

Parameters

NameType
typestring

Returns

boolean


on

on(type, callback): void

增加监听事件, 功能完全等同于addEventListener,一种简写

Parameters

NameTypeDescription
typestring事件类型
callbackFunction事件处理函数

Returns

void


removeEventListener

removeEventListener(type, callback): any

移除一个事件监听

Parameters

NameType
typestring
callbackFunction

Returns

any