title: Proper way to dynamically add functions to ES6 classes
body: <p>I have a simple class with a single method <code>exec(arg1,..,argn)</code> and I want to have a number of alias methods which call <code>exec</code> with predefined argument values (e.g. <code>exec_sync = exec.bind(this, true)</code>). </p>
  
  <p>The following does the trick:</p>
  
  <pre class="lang-js prettyprint-override"><code>class Executor {
    constructor() {
      this.exec_sync = this.exec.bind(this, true);
    }
  
    exec(sync, cmd, args/* ... */) {
      // impl
    }
  }
  </code></pre>
  
  <p><strong>But</strong> I don't know if this is a good idea or if this is idiomatic to ES6.</p>
  
  <p><strong>UDATE:</strong></p>
  
  <p>In a real-life example I have two nested loops with respectively 3 and 4 loops, which are used to dynamically add a total number of 12 alias methods to the class. It would be a cumbersome task to explicitly define the alias methods when you actually can take advantage of JS being a prototype-based programming language.</p>
  
  <p><strong>UPDATE 2 - EXAMPLE:</strong></p>
  
  <p>Suppose we have have a simple HTTP client with a method <code>request(method, body)</code> and we want to provide alias methods for <code>GET</code>, <code>PUT</code>, etc. It would look something like the following:</p>
  
  <pre class="lang-js prettyprint-override"><code>class HTTP {
    constructor() {
      ['GET', 'PUT', 'POST', 'DEL'].forEach((method) =&gt; {
        this[method] = this.request.bind(this, method);
      }, this);
    }
  
    request(method, body) {
      // execute the HTTP request
    }
  }
  </code></pre>