title: Javascript Instances and this
body: <p>I am writing a little tool in node.js, here is the part that is bothering me:</p>
  
  <pre><code>function Active(name, options, data){
    events.EventEmitter.call(this);
    var that = this;
    that.name = name;
    that.options = options;
    that.data = data;
    that.getData();
    that.on('ActiveStart', that.createLogFile);
    that.on('ActiveDone', that.removeLogFile);
    function callback() {
      that.emit('ActiveDone');
    }
    var getData = function() {
    // starts other processes outside of the scope of this function
    // callback() gets passed around and called from outside function
    }
    getData();
   }
  
  
  util.inherits(Active,events.EventEmitter);
  
  Active.prototype.createLogFile = function () {
    this.filename = this.name + '-' + this.options + '.log';
    fs.outputFile('./log/' + this.filename,data,function (err) { // fs-extra
      if(err) return console.log(err);
    });
  };
  
  Active.prototype.removeLogFile = function () {
    fs.remove('./log/' + this.filename,function (err) {
      if(err) return console.log(err);
    });
  };
  
  
  Active.prototype.findData = function () {
      var that = this;
  
      routes.findOneAndUpdate({},update,{sort: _sort},function (err,doc) { // update and _sort are in 'global' scope
        if(err) return console.log(err);
        that.emit('ActiveStart',doc.info,doc.data); // the variables are for a different event handler
      });
  
  };
  </code></pre>
  
  <p>Active has some other methods which do the lifting, I am having trouble with the log file though. I start the process with </p>
  
  <pre><code>new Active('hello','123','data');
  </code></pre>
  
  <p>and the logfile is created. As long as I have just one instance of Active, everything is fine. If I start</p>
  
  <pre><code>new Active('second','456','moredata');
  </code></pre>
  
  <p>before the first log is deleted, the removeLogFile later removes the second logfile because <code>this</code> does not point to the first instance, but the second. Why is that? Dont I create two different scopes with the <code>new</code> operator?</p>