title: Extend Array with custom method
body: <p>I want to extend an <code>Array</code> so as to add custom methods to it. </p>
  
  <p>Here is my attempt at doing so:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class DataArray extends Array {
    constructor() {
      super();
    }
    add(item) {
      this.push(item);
    }
  }
  
  const dataArray = new DataArray();
  dataArray.add(1);</code></pre>
  </div>
  </div>
  </p>
  
  <p>But gives the error <code>Uncaught TypeError: dataArray.add is not a function</code></p>
  
  <p>The error happens only when I use Babel or Typescript to compile the code.</p>