[name]

自定义对象的 JavaScript 事件。
[link:https://github.com/mrdoob/eventdispatcher.js Eventdispatcher on GitHub]

示例

// 为自定义对象添加事件 var Car = function () { this.start = function () { this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } ); }; }; // 将 EventDispatcher.prototype 与自定义对象 prototype 进行混合 Object.assign( Car.prototype, EventDispatcher.prototype ); // 使用自定义对象的事件 var car = new Car(); car.addEventListener( 'start', function ( event ) { alert( event.message ); } ); car.start();

构造函数

[name]()

创建 EventDispatcher 对象。

方法

[method:null addEventListener]( [param:String type], [param:Function listener] )

type - 需要添加监听的事件类型。
listener - 事件发生时被调用到的函数。

为指定事件增加监听函数。

[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )

type - 需要被监听的事件类型。
listener - 事件发生时被调用到的函数。

检查监听函数是否已经添加到指定事件。

[method:null removeEventListener]( [param:String type], [param:Function listener] )

type - 需要移除监听的事件类型。
listener - 需要被移除的监听函数。

从指定事件类型中移除监听函数。

[method:null dispatchEvent]( [param:object event] )

event - 将被触发的事件。

触发一个事件。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]