File: EventDispatcher.html

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (102 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<base href="../../../" />
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
	</head>
	<body>
		<h1>[name]</h1>

		<p class="desc">
			自定义对象的 JavaScript 事件。<br />
			[link:https://github.com/mrdoob/eventdispatcher.js Eventdispatcher on GitHub]
		</p>

		<h2>示例</h2>

		<code>
// 为自定义对象添加事件

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();
		</code>

		<h2>构造函数</h2>

		<h3>[name]()</h3>
		<p>
		创建 EventDispatcher 对象。
		</p>


		<h2>方法</h2>

		<h3>[method:null addEventListener]( [param:String type], [param:Function listener] )</h3>
		<p>
		type - 需要添加监听的事件类型。<br />
		listener - 事件发生时被调用到的函数。
		</p>
		<p>
		为指定事件增加监听函数。
		</p>

		<h3>[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )</h3>
		<p>
		type - 需要被监听的事件类型。<br />
		listener - 事件发生时被调用到的函数。
		</p>
		<p>
		检查监听函数是否已经添加到指定事件。
		</p>

		<h3>[method:null removeEventListener]( [param:String type], [param:Function listener] )</h3>
		<p>
		type - 需要移除监听的事件类型。<br />
		listener - 需要被移除的监听函数。
		</p>
		<p>
		从指定事件类型中移除监听函数。
		</p>

		<h3>[method:null dispatchEvent]( [param:object event] )</h3>
		<p>
		event - 将被触发的事件。
		</p>
		<p>
		触发一个事件。
		</p>


		<h2>源代码</h2>

		<p>
			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
		</p>
	</body>
</html>