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
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
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.
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
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
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
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);
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
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
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
= [
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
11 matches
Mail list logo