<table class="text">
<tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 代码!!! ``` function EventDispatcher() { this.events = {}; } EventDispatcher.prototype.addEventListener = function(type,handler) { if (typeof handler != 'function') return; this.events[type] = handler; }; EventDispatcher.prototype.dispatchEvent = function(type,body) { var e = {}; e.body = body; this.events[type](e); }; var d = new EventDispatcher(); d.addEventListener('testEvent',function(e){ console.log('callback fired-----' + e.body); }); d.dispatchEvent('testEvent','213123123'); ``` 完毕 收工~~