title: Node.JS EventEmitter Listener Must be a Function
body: <p>I am getting an error when attempting to setup listeners within a function.  I have reviewed other code that this works for, but can't seem to get it to work for my purposes.  </p>
  
  <p>This is a simplified version of what I am attempting to get done.  </p>
  
  <pre><code>var ticketGenerator = function(){
      var self = this;
      console.log('ticket generator');
      var rows = "";
      this.emit("getQueue")
  
      var _getQueue = function(){
      console.log('Getting Queue');
      var connection = mysql.createConnection({
          //Connection Data
      }); 
      connection.connect();
      connection.query("SELECT * FROM `queue` WHERE `run` = 0 ORDER BY `queueID` ASC LIMIT 1", function(err, rows, fields){
          if(err){
              //self.emit("error", "Unable to get data from the database.")
              console.log(err);
          }
          else if(typeof rows[0] == "undefined"){
              console.log("Waiting to run again.");
              connection.end();
              setTimeout(function(){ticketGenerator()}, 60000);
          }
          else{
              console.log("Passing Ticket Data");
              self.emit("newTicketData", rows);
              connection.end();
          }
      })
      };
  
      this.on("getQueue", _getQueue);
  }
  </code></pre>
  
  <p>I cannot get it to run the function for _getQueue.  When I put in the listener _getQueue() it will run the function, but throws an error (TypeError: listener must be a function).  I'm not sure what I am doing wrong as I have seen other code written in this way that is working.  </p>
  
  <p>I have verified that I have the listeners setup with this.on('newListener' . . . ). I assume that since I can get it to call the function when changing the name on the listener that the emitter is doing it's job as well.  </p>
  
  <p>Note that this ticketGenerator function is being called from another file using requires.  I don't know if this will affect the solution for this issue, but figured that detail may be important.  </p>
  
  <p>---------------EDIT----------------
  I ended up figuring this out after I posted this.  I needed to call a constructor for these events to go through.  The code looks like the following.  </p>
  
  <pre><code>events.EventEmitter.call(this);
  </code></pre>
  
  <p>I couldn't answer my own question due to rep, but will update the answer area when I can.  </p>