title: Typescript issue using 'this' inside class constructor for instance method
body: <p>I have a very simple use case in TypeScript: 
  A class, with a constructor, and an instance method. </p>
  
  <p>I want to call this instance method from the constructor, but using "this" resolves incorrectly. </p>
  
  <p>What is the proper way to have a class with instance methods, and call them from the constructor? </p>
  
  <p>I have a UMD module (defined in my tsconfig as the module type to compile as).</p>
  
  <p>I have the following code: </p>
  
  <pre><code>export namespace TestNS {
      export class TestClass {
          // Fields
          testValue: string;
  
          constructor(val: string) {
              this.testValue = val;
              this.privateMethod();
          }
  
          private privateMethod() {
              console.log("private instance method");
          }
      }//TestClass class
  }
  </code></pre>
  
  <p>And it compiles to:</p>
  
  <pre><code>(function (factory) {
      if (typeof module === "object" &amp;&amp; typeof module.exports === "object") {
          var v = factory(require, exports);
          if (v !== undefined) module.exports = v;
      }
      else if (typeof define === "function" &amp;&amp; define.amd) {
          define(["require", "exports"], factory);
      }
  })(function (require, exports) {
      "use strict";
      Object.defineProperty(exports, "__esModule", { value: true });
      var TestNS;
      (function (TestNS) {
          var TestClass = /** @class */ (function () {
              function TestClass(val) {
                  this.testValue = val;
                  this.privateMethod();
              }
              TestClass.prototype.privateMethod = function () {
                  console.log("private instance method");
              };
              return TestClass;
          }()); //TestClass class
          TestNS.TestClass = TestClass;
      })(TestNS = exports.TestNS || (exports.TestNS = {}));
  });
  //# sourceMappingURL=Test.js.map
  </code></pre>
  
  <p>I call it using:</p>
  
  <pre><code>var ex = new TestNS.TestClass("test");
  </code></pre>
  
  <p>When invoking, I get an error that privateMethod cannot be found.
  When debugging the raw js code in the browser, <code>this</code> in the class constructor seems to refer to "TestNS" namespace object, and NOT my TestClass instance I would expect. Why would this be? This seems like an obvious issue if I can't namespace, AND use class instance members. </p>
  
  <p>What am I doing wrong here? (I want to enforce that kind of namespacing to organize objects and such for a larger project later)</p>
  
  <p>Edit: To clarify how this code is loaded, I'll provide those details. </p>
  
  <p><strong>tsconfig.json</strong></p>
  
  <pre><code>{
    "compilerOptions": {
      "baseUrl": "./js",
      "target": "es5",
      "sourceMap": true,
      "typeRoots" : ["./js/lib/@types"],
      "module": "UMD"
    },
    "exclude": [
      "node_modules"
    ]
  }
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
      &lt;script src="require.js"&gt;&lt;/script&gt;
      &lt;!-- Data main attribute avoided due to some environment constraints (ie: a CMS) --&gt;
      &lt;script src="main.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;p&gt;Example Text&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>requirejs.config({
      baseUrl: "js",
      map: {
          '*': {
              'Test': 'modules/Test',
          }
      }
  });
  
  requirejs(["Test"],function(TestNS) {
      var t = new TestNS.TestClass("value");
  }
  </code></pre>