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 (this[Array.derivedArrayKey]) {
A = this[Array.derivedArrayKey]();
} else if (typeof this.constructor === "function") {
A = new this.constructor();
} else {
A = [ ];
}
Creating a subclass this way (i.e., using @derivedArrayKey) produces code whose
meaning is more obvious (to me) than the code below.
>>> function createArraySubclass(proto,...values) {
>>> return proto <| [...values].{
>>> [Array.derivedArrayKey](){return proto<| [ ]}
>>> }
>>> }
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss