title: Sharing Variables between functions in ES6 Classes
body: <p>I'm dabbling around with ES6 Syntax in Node.js. As a starting point I just tried creating a simple class that configures and returns an Express server - not sure if this would be good or not in production, though.</p>
  
  <p>I'm having trouble with accessing the classes member variables in other functions. Take a look at the code below:</p>
  
  <pre><code>import express from 'express'
  import http from 'http'
  
  const _server = null
  const _app = null
  
  class HttpServer {
  
      constructor (port) {
          this._port = port;
  
          if (this._app === null) {
              this._app = express()
          }
  
          if (this._server === null) {
              this._server = http.createServer(this._app)
          }
  
          return this._server
      }
  
      start (callback) {
  
          this._server.listen(this._port, (error) =&gt; {
              return callback(error)
          })
      }
  
  }
  
  export default HttpServer
  </code></pre>
  
  <p>The constructor seems to be working okay, although when I call the <code>start</code> method I get an error that the variable <code>this._server</code> is <code>undefined</code>. I thought the <code>this</code> keyword would be able to access the variables. I have tried replacing the <code>this</code> accessing method to using <code>HttpServer._server</code> but with no luck. Any tips or advice would be appreciated!</p>
  
  <p>If I've made silly mistakes, please forgive me, I haven't hopped on the ES6 train before this!</p>