This commit is contained in:
Ryan McGrath 2011-02-18 04:25:06 -05:00
commit 5ed915c6c5
8 changed files with 329 additions and 0 deletions

20
events/listing_2.js Normal file
View file

@ -0,0 +1,20 @@
var events = require('events'),
util = require('util');
var Foo = function(initial_no) { this.count = initial_no; };
Foo.prototype = new events.EventEmitter;
Foo.prototype.increment = function() {
var self = this;
setInterval(function() {
if(self.count % 2 === 0) self.emit('even');
self.count++;
}, 300);
};
var lol = new Foo(1);
lol.on('even', function() {
util.puts('Number is even! :: ' + this.count);
}).increment();