title: TypeError: Cannot set property <function> of undefined
body: <p>Here, i am trying to construct object in javascript.
  But i am getting runtime error as :</p>
  
  <pre><code>TypeError: Cannot set property 'functWriteToLogFile' of undefined
  </code></pre>
  
  <p>My javascript object as follow :</p>
  
  <pre><code>function SetAstAppLog(logFolderPath,fileNamePrefix,fileSize,logStreamObject) {
  .
  .
  .
  .
      this.functWriteToLogFile = function (fileNamePrefix, message) {
          console.log("functWriteToLogFile " + message);
          var currLogStreamObject =  initLogPath(fileNamePrefix);
          console.log("********************");
          console.log(fileNamePrefix);
          console.log(filePath);
          currLogStreamObject.write(message + '\n');
          this.emit('written');
      };
  
      initLogPath(fileNamePrefix);// Set log path on creation of new object.
      this.emit('objCreated');
  }
  </code></pre>
  
  <p>I am want to access <code>functWriteToLogFile</code> in other functions like :</p>
  
  <pre><code>SetAstAppLog.prototype.funcLogErrors = function (fileNamePrefix,errLevel,err,req) {
     //make new json object here then call functWriteToLogFile
     this.functWriteToLogFile(fileNamePrefix, JSON.stringify(logErrorObj));
  };
  </code></pre>
  
  <p><br>
  I am not able to find out my mistake here.</p>
  
  <p>Can anyone help me to solve this issue?</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>I am calling this function in following way :</p>
  
  <pre><code>var SetAstAppLog = require('astAppLog')();
  var fileSize = 1024;
  
  
  var objCommLogger = new SetAstAppLog(logFolderPath,logCommFilePrefix,fileSize,logCommMsg);
  </code></pre>