title: Typescript or babel plugin to transform a ES6 class to function with scoped variables acting as private properties pattern
body: <p>Background: Not so long ago functions with scoped variables acting as private properties or methods was an extremely efficient way to create classes in JavaScript. Today's standards is to use the more verbose and file size inefficient approach of using <code>prototype</code> and the <code>this</code> keyword. Also the modern approach it's less flexible.</p>
  
  <p>Is there any transform plugin to convert a ES6 class into a function with scoped variables acting as instance private variables? In code:</p>
  
  <pre class="lang-js prettyprint-override"><code>class MyClass { 
    private myProp = "hello "; // or #myProp with new proposed syntax
    private myProp2 = "World"; // or #myProp2 with new proposed syntax
  
    print() {
      console.log(this.myProp + this.myProp2);
    }
  }
  
  </code></pre>
  
  <p>into:</p>
  
  <pre class="lang-js prettyprint-override"><code>function MyClass() {
    var self = this,
        myProp = "hello ",
        myProp2 = "World";
  
    self.print = function() {
      console.log(myProp + myProp2);
    }
  }
  </code></pre>
  
  <p>Any suggestion?</p>
  
  <p><strong>Note</strong>: I'm aware of how JavaScript prototype works and that the second approach doesn't use it. The whole point of this question is to find an <em>transpilation</em> alternative to the prototype pattern as shown above, which is 100% valid and equivalent to the typical use cases of classes. I.e. <code>myClass.print();</code>.</p>
  
  <p><strong>Update 2</strong>: For those considering the memory footprint they're right. The JavaScript engine performance is not a problem since the not-so-old and modern engines take this approaches into account.</p>
  
  <p><strong>Update 3</strong>: Also, this pattern can offer class inheritance, public/private static methods and it's fully compatible with the "instanceof" operator on the base class and the parent classes.</p>