forked from Olical/EventEmitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
54 lines (41 loc) · 1.23 KB
/
test.html
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
<!DOCTYPE html>
<html lang='en'>
<head>
<title>EventEmitter testing</title>
<meta name='author' content='Oliver Caldwell' />
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
</head>
<body>
<script type='text/javascript' src='EventEmitter.js'></script>
<script type='text/javascript'>
// Initialise the class
var emitter = new EventEmitter();
// Create a test function
function show(msg) {
alert(msg);
}
// Add the listener
emitter.addListener('message', show);
// Trigger the event
emitter.emit('message', 'Basic event');
// Remove the listener
emitter.removeListener('message', show);
// Trigger the event
emitter.emit('message', 'Should not show');
// Add the listener
emitter.on('message', show);
// Trigger the event
emitter.emit('message', 'Using alias');
// Remove all listeners
emitter.removeAllListeners('message');
// Trigger the event
emitter.emit('message', 'Should not show');
// Add the listener
emitter.once('message', show);
// Trigger the event
emitter.emit('message', 'Using once');
// Trigger the event
emitter.emit('message', 'Should not show');
</script>
</body>
</html>