Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v1.1.2
Fetching contributors…

Cannot retrieve contributors at this time

54 lines (41 sloc) 1.262 kb
<!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>
Jump to Line
Something went wrong with that request. Please try again.