On Jun 10, 2015, at 9:16 AM, C. Scott Ananian wrote:
> On Wed, Jun 10, 2015 at 11:46 AM, Domenic Denicola <[email protected]> wrote:
> Regardless of whether or not you agree, that was the original motivation for
> its introduction.
>
>
> https://twitter.com/awbjs/status/535962895532584960 says:
> ES6 final tweaks #8: Smalltalk-like species pattern used in Array methods,
> etc. to determine constructor for derived objects.
> https://esdiscuss.org/notes/2014-11-18 discusses species in the context of
> `Array.prototype` methods.
> And https://esdiscuss.org/notes/2014-11-19 says:
> Allen Wirfs-Brock: Smalltalk uses an abstract above that has a species
> property to determine what to create.
>
> That's all I know of it. I wasn't there, obviously, and you were. But this
> is the first I've ever heard of using @@species for constructor signature
> modification. It's hard to reconstruct reasoning from meeting notes and
> tweets.
That's correct. `species` is intended for use when a subclass constructor
wants to use something other than itself as the constructor for objects derived
from the subclass instances. Using `species` to select a constructor higher in
a class hierarchy for derived instances is a fine thing to so. For example, a
"SortedArray" might choose that operations like `map` should produce the more
general Array instances rather than SortedArray instances.
Using `species` to modify constructor signatures was not one of its intended
use-cases, however, it might be possible to use it for that purpose.
Note that the uses of `species` in the ES6 spec all assume that the signature
of the returned constructor is the same as the base class constructor.
However, a way around that might be to have a `species` method that was an
adaptor of the expected constructor signature to some other signature pattern.
For example,
LabelledPromise[Symbol.species] = function() {
ctor = this;
return function(executor) {
if (new.target === undefined) throw TypeError("Can't call a class
constructor");
return Reflect.construct(ctor, [ctor.defaultLabel, executor],
new.target)
}
};
LabelledPromise.defaultLabel = "default label";
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss