var irc = require('irc');

function Bot(settings) {
  this.settings = settings;
  console.log('Connecting to IRC server ' + settings.irc.host + ' with nick ' +
      settings.irc.nick);


  this.irc = new irc.Client(settings.irc.host, settings.irc.nick, {
    channels: [settings.irc.channel],
  });
  
  var obj = this;
  this.irc.on('error', obj.onError);
}

exports.Bot = Bot;

Bot.prototype.onError = function(msg) {
  console.error('Error: %s: %s', msg.command, msg.args.join(' '));
}


var irc = require('irc');

function Bot(settings) {
  this.settings = settings;
  console.log('Connecting to IRC server ' + settings.irc.host + ' with nick ' +
      settings.irc.nick);

  this.irc = new irc.Client(settings.irc.host, settings.irc.nick, {
    channels: [settings.irc.channel],
  });
  this.irc.addListener('error', function(msg) {
    console.error('Error: %s: %s', msg.command, msg.args.join(' '));
  });
}

exports.Bot = Bot;


--- 
+++ 
@@ -5,13 +5,18 @@
   console.log('Connecting to IRC server ' + settings.irc.host + ' with nick ' +
       settings.irc.nick);
 
+
   this.irc = new irc.Client(settings.irc.host, settings.irc.nick, {
     channels: [settings.irc.channel],
   });
-  this.irc.addListener('error', function(msg) {
-    console.error('Error: %s: %s', msg.command, msg.args.join(' '));
-  });
+  
+  var obj = this;
+  this.irc.on('error', obj.onError);
 }
 
 exports.Bot = Bot;
 
+Bot.prototype.onError = function(msg) {
+  console.error('Error: %s: %s', msg.command, msg.args.join(' '));
+}
+
Move onError callback to a method
