Re: Subclassing an array and array methods

2011-11-12 Thread Axel Rauschmayer
I misunderstood the problem: I thought there was something peculiar about an array instance (the first object in the prototype chain), but it’s about the Array constructor not being invocable as a function (right?). Wouldn’t it be easier to introduce a generic method Array.prototype.init() that

Re: Subclassing an array and array methods

2011-11-12 Thread Allen Wirfs-Brock
On Nov 12, 2011, at 9:38 AM, Axel Rauschmayer wrote: I misunderstood the problem: I thought there was something peculiar about an array instance (the first object in the prototype chain), but it’s about the Array constructor not being invocable as a function (right?). I'm not sure what you

Re: Subclassing an array and array methods

2011-11-12 Thread Axel Rauschmayer
I misunderstood the problem: I thought there was something peculiar about an array instance (the first object in the prototype chain), but it’s about the Array constructor not being invocable as a function (right?). I'm not sure what you mean about not invocable as a function.

Re: Subclassing an array and array methods

2011-11-12 Thread Rick Waldron
snip Use case 2: Avoid the length pitfall: var arr = new Array().init(5); // same as [5] See: Array.of() http://wiki.ecmascript.org/doku.php?id=strawman:array_extras snip ___ es-discuss mailing list es-discuss@mozilla.org

Subclassing an array and array methods

2011-11-11 Thread Jake Verbaten
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

Re: Subclassing an array and array methods

2011-11-11 Thread Allen Wirfs-Brock
My intent is to use a private name property to allow an object to provide a constructor for new arrays derived from it. something along the lines of: function createArraySubclass(proto,...values) { return proto | [...values].{ [Array.derivedArrayKey](){return proto| [ ]} } } The

Re: Subclassing an array and array methods

2011-11-11 Thread Axel Rauschmayer
function createArraySubclass(proto,...values) { return proto | [...values].{ [Array.derivedArrayKey](){return proto| [ ]} } } I’m curious: Why wouldn’t one extend Array, instead? function SubArray() { } SubArray.prototype = Object.create(Array.prototype);

Re: Subclassing an array and array methods

2011-11-11 Thread Allen Wirfs-Brock
On Nov 11, 2011, at 9:47 AM, Axel Rauschmayer wrote: function createArraySubclass(proto,...values) { return proto | [...values].{ [Array.derivedArrayKey](){return proto| [ ]} } } I’m curious: Why wouldn’t one extend Array, instead? the problem is with built-ins like

Re: Subclassing an array and array methods

2011-11-11 Thread Axel Rauschmayer
Got it, related to what you solve in generic classes with This-types (covariance vs. contravariance...). // assume |this| is the source collection if (this[Array.derivedArrayKey]) A = this[Array.derivedArrayKey](); else A = [ ]; Another possibility: if

Re: Subclassing an array and array methods

2011-11-11 Thread Allen Wirfs-Brock
On Nov 11, 2011, at 10:52 AM, Axel Rauschmayer wrote: Got it, related to what you solve in generic classes with This-types (covariance vs. contravariance...). // assume |this| is the source collection if (this[Array.derivedArrayKey]) A = this[Array.derivedArrayKey](); else A = [

Re: Subclassing an array and array methods

2011-11-11 Thread Brendan Eich
On Nov 11, 2011, at 11:07 AM, Allen Wirfs-Brock wrote: On Nov 11, 2011, at 10:52 AM, Axel Rauschmayer wrote: Got it, related to what you solve in generic classes with This-types (covariance vs. contravariance...). // assume |this| is the source collection if