Why doesn't
myInstance.first() instanceof MyClass
return true?
Because first
calls slice
, and Array.prototype.slice
does always return an Array
. You will need to overwrite it with a method that wraps it in a MyClass
again:
class MyClass extends Array
constructor: (obj) -> @push.apply @, obj
slice: () -> new MyClass super
splice: () -> new MyClass super
concat: () -> new MyClass super
filter: () -> new MyClass super
map: () -> new MyClass super
first: -> @slice 0, 1
And notice that subclassing Array
does not work.