title: Have private properties & methods in ES6 classes
body: <p>I'm just trying out ES6 and want to rewrite a part of code written in regular javascript to ES6. And now, I'm stuck while trying to re-write the private properties and methods in ES6 classes. It seems like classes in ES6 doesn't explicitly provide anything to have private data or methods. </p>
  
  <p>Also, I checked this thread: <a href="https://stackoverflow.com/questions/22156326/private-properties-in-javascript-es6-classes">Private properties in JavaScript ES6 classes</a> and found out that we could use <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/WeakMap" rel="noreferrer" title="WeakMap">WeakMap</a> to store private data. Which is sort of weird but still it can be a work around. And I did manage to use it for private data. </p>
  
  <p><strong>But what about private methods? What is the recommended way to have private methods</strong> (or even protected methods) in ES6 classes? </p>
  
  <p>I would appreciate if anyone can show me a <strong>clean</strong> way to rewrite this part of code using ES6 class along with the private methods. </p>
  
  <p>Thanks. </p>
  
  <p>Here's the plain old javascript code: </p>
  
  <pre><code>function Deferred() {
  
      // Private data
      var isPending;
      var handlers = {
          resolve: [],
          reject: [],
          notify: []
      };
  
      // Initialize the instance
      init();
  
      function init() {
          isPending = true;
          this.promise = new Promise(this);
      }
  
      // Public methods
      this.resolve = function(value) {
          trigger('resolve', value);
      };
  
      this.reject = function(reason) {
          trigger('reject', reason);
      };
  
      this.notify = function(value) {
          trigger('notify', value);
      };
  
      this.on = function(event, handler) {
          ...
      };
  
      // Private method
      function trigger (event, params) {
          ...
      }
  }
  </code></pre>