title: Extending an Array properly, keeping the instance of subclass
body: <p>I've written a class trying to extend the native Javascript <code>Array</code> class with a custom class, let's call it <code>MyClass</code>. This is basically what it looks like:</p>
  
  <pre><code>class MyClass extends Array
  
    constructor: (obj) -&gt; @push.apply @, obj
  
    first: -&gt; @slice 0, 1
  </code></pre>
  
  <p>Instantiating the class is no problem. Running this in the console:</p>
  
  <pre><code>var myInstance = new MyClass(["1", "2"])
  &gt; ["1", "2"]
  myInstance instanceof MyClass
  &gt; true
  myInstance instanceof Array
  &gt; true
  </code></pre>
  
  <p>works as exptected.</p>
  
  <p>The problem is that if I run:</p>
  
  <pre><code>myInstance.first()
  &gt; ["1"] // as expected
  myInstance.first() instanceof MyClass
  &gt; false // not expected
  myInstance.first() instanceof Array
  &gt; true
  </code></pre>
  
  <p>the returned value is no longer an instance of MyClass.</p>
  
  <p>I've also tried <code>@__proto__.first = @first</code> in the constructor function and <code>first: -&gt; @slice.call @, 0, 1</code>. But with no success.</p>
  
  <p>Why doesn't <code>myInstance.first() instanceof MyClass</code> return <code>true</code>?</p>