title: promise js function call another function in same class
body: <p>I am trying to build a custom logger and what I am trying to do as after I take a screenshot I want to call my logger function to log the image name. When I am in the then of the promise it cannot see all the functions in the class</p>
  
  <pre><code>module.exports = {
      takeScreenshot: function(driver, filename) {
          driver.takeScreenshot().then(function(data) {
            name = filename || 'ss.png';
            var screenshotPath = 'results/screenshots/';
            fs.writeFileSync(screenshotPath + name, data, 'base64');
            return screenshotPath + name;
          }).then(function(e) {
              this.logger(e, "true");
          });
      },
  
      logger: function(log, screenshot) {
        isScreenshot = screenshot || "false";
        var obj = {};
        if (isScreenshot == "true") {
          obj[testName.replace(/ /g,'')] = {
              logs: "",
              screenshot: "&lt;img src=\"" +log+ "\" class=\"test-img\" /&gt;"
          };
          logger.push(obj);
        } else {
          obj[testName.replace(/ /g,'')] = {
              logs: "&lt;span class=\"test-log\"&gt;" +log + "&lt;/span&gt;",
              screenshot: ''
          };
          logger.push(obj);
        }
     }
  }
  </code></pre>
  
  <p>Basically its not seeing the logger method. What am I missing? Thanks</p>