How can I extend the Array class in Babel?
<p>I'd like to define a shortcut method for inspecting the end of a stack.</p>

<p>The following works in Firefox:</p>

<pre><code>const Stack = class extends Array {
  last() {
    return this[this.length - 1];
  }
}
</code></pre>

<p>However, after compiling this with Babel, it doesn't work:</p>

<pre><code>var Stack = function (_Array) {
  _inherits(Stack, _Array);

  function Stack() {
    _classCallCheck(this, Stack);

    return _possibleConstructorReturn(this, Object.getPrototypeOf(Stack).apply(this, arguments));
  }

  _createClass(Stack, [{
    key: 'last',
    value: function last() {
      return this[this.length - 1];
    }
  }]);

  return Stack;
}(Array);


console.log(Stack.prototype.last); // works
console.log((new Stack()).last); // doesn't work
Array.prototype.last = Stack.prototype.last;
console.log((new Stack()).last); // works
</code></pre>

<p>For some reason, I can add functions to the new prototype, but they won't be available to instances of that prototype unless they're inserted directly into the Array prototype (which is obviously bad practice due to potential side effects).</p>

<hr>

<p><strong>Update</strong>: There might be several ways to get around this (including Proxy objects, or extending the prototype manually instead of using <code>extends</code>), but since my <code>Stack</code> doesn't really <em>need</em> most of the Array methods, I'm now simply using a wrapper.</p>

<pre><code>  const Stack = class {
    constructor(...x) {
      this.arr = [...x];
    }
    pop() {
      return this.arr.pop();
    }
    push(...x) {
      return this.arr.push(...x);
    }
    top() {
      return this.arr[this.arr.length - 1];
    }
    size() {
      return this.arr.length;
    }
  }
</code></pre>