Why does my ES6 (using Babel) class say `this` is undefined in an instance method? : <p>I am building an application in Node using Hapi.JS.</p>

<p>I have a class for an authentication plugin that is giving me all sorts of problems. When I attempt to reference <code>this</code> from within a method on the class, I get an error saying that <code>this</code> is undefined. Why is this happening?</p>

<p>An excerpt:</p>

<pre><code>class OAuth {

  constructor () {}

  register (server, err, next) {
    this.server = server;
    this.registerRoutes();
  }

  registerRoutes () {
    console.log(this.server.route);
    this.server.route([
      {
          method: 'POST',
          path: '/oauth/token',
          config: {
              auth: false,
              handler: function(request,reply){
                console.log("test");
                reply("test");
              }
            }
      },
      {
        method: 'GET',
        path: '/test',
        config: {
          auth: false,
          handler: function(request,reply){
            console.log("test");
            reply("test");
          }
        }
      }
    ]);
  }
}
module.exports = new OAuth();
</code></pre>

<p>Elsewhere this is being called like:</p>

<pre><code>const oauth = require('./oauth');
oauth.register(server);
</code></pre>

<p>Every time the register function is called, I receive this error:</p>

<pre><code>TypeError: Cannot set property 'server' of undefined
</code></pre>

<p>Why on earth is my instance not working?</p>
