Skip to content

Commit

Permalink
When just forwarding events on the streams to the instance we should …
Browse files Browse the repository at this point in the history
…use Function.prototype.bind so as not to miss any arguments that might be of use to the user. For instance, previously the exception argument to the error event was completely discarded.
  • Loading branch information
tedeh committed Oct 23, 2011
1 parent d96f141 commit 23ae491
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/ya-csv.js
Expand Up @@ -18,9 +18,9 @@ var CsvReader = csv.CsvReader = function(readStream, options) {
};

if (readStream) {
readStream.addListener('data', function(data) { self.parse(data) });
readStream.addListener('error', function() { self.emit('error') });
readStream.addListener('end', function() { self.end() });
readStream.addListener('data', this.parse.bind(this));
readStream.addListener('error', this.emit.bind(this, 'error'));
readStream.addListener('end', this.end.bind(this));
}
};
sys.inherits(CsvReader, events.EventEmitter);
Expand Down Expand Up @@ -186,9 +186,9 @@ var CsvWriter = csv.CsvWriter = function(writeStream, options) {
writeStream.setEncoding(self.encoding);
}

writeStream.addListener('drain', function() { self.emit('drain') });
writeStream.addListener('error', function() { self.emit('error') });
writeStream.addListener('close', function() { self.emit('close') });
writeStream.addListener('drain', this.emit.bind(this, 'drain'));
writeStream.addListener('error', this.emit.bind(this, 'error'));
writeStream.addListener('close', this.emit.bind(this, 'close'));
};
sys.inherits(CsvWriter, events.EventEmitter);

Expand Down

0 comments on commit 23ae491

Please sign in to comment.