Subclassing an array and array methods

Jake Verbaten raynos2 at
Fri Nov 11 06:08:21 PST 2011

In es-next we should be able to subclass an array

function createArraySubclass(proto, ...values) {
  return proto <| [...values];

However when we call `instanceOfSubArray.filter(...)` this method returns a
new Array rather then a new SubArray.

It would seem frustrating to have to overwrite all array methods that
return arrays and make them return subarrays.

Can we have array methods returning new instance of [[Prototype]] to make
it easier to overwrite the build in?

However this should only apply to true array subclasses. In the above
example I would assume the [[Class]] of the object is Array. It should not
apply to []

Do we have other situations where it would make sense to return an instance
of whatever prototype your operation on rather then a hardcoded new X ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list