-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rationalizing Symbol.species #1313
Comments
One possible alternative: decide arrays are just weird (as they are anyway, for cross-realm web compat reasons), and we should continue to make new generic methods use |
One possible alternative: decide that |
One possible alternative: decide that We might consider using MDN's description for
|
One possible alternative: change the behavior of We could rationalize this by saying that those methods need to have their own magic for cross-realm stuff for web-compat reasons, which is true. |
One possible alternative: consider |
An example of a case where I once had a Promise subclass where it was important to spawn ordinary promises (or else they’d have cycled). I could have done this by overriding |
Nope. |
I too have a Promise subclass that benefits from Symbol.species. I hope it doesn't go away. |
@domenic It delegates to I think the point about reducing forward compat risks likely stands even if the example I gave was poor. Do you think that is not the case? Or that it is, but its value doesn’t outweight the cost of |
|
I gather you feel strongly about this haha! I’d like to understand why you concluded that it was a legacy design mistake though. (I read through #1289, but it didn’t quite fill in the gap — anybody have a link to prior discussion that would clarify?) |
Yeah, it's been unclear to me too; @domenic, I've seen you express this strong opinion against AWB expressed in #1289 pretty clearly that Do you object to the behavior just for non-subclasses of Array? Or do you dislike it in general? Without this or something like it, how do we deal with Array-likes that can't subclass Array? Is your opinion that such classes should just manually re-implement all of the Array methods, and be updated whenever a new Array method is added? |
|
OK, it sounds like there are some uses of Promise subclassing, but it's not clear whether species is necessary to achieve the desired functionality or whether overriding other methods would be sufficient. Are there known use cases for other classes creating an instance of the subclass from methods through species, e.g., TypedArray, Array or RegExp? |
We can certainly justify the brand-check in ArraySpeciesCreate() as a way to support the legacy way to apply array methods to non-arrays, casting the result into an array in the process. But I don’t think it is a good reason to extend such brand-check to new stuff; we should rather encourage explicit casting functions à la Another thing that bugs me is that, when SpeciesConstructor() or similar is invoked, a default constructor is provided. I think it is a design error (notwithstanding legacy stuff like arrays), because you can’t really guess what the intended constructor is. For example: Array.prototype.slice.call(nodeList) will cast a NodeList instance into an Array object, but class BetterArray extends Array { }
BetterArray.prototype.slice.call(nodeList) will confusingly not cast a NodeList instance into a BetterArray object. More generally, any method whose algorithm contains an explicit reference to its class/constructor is expected to behave surprisingly when inherited by a subclass. |
See further discussion of this topic in https://github.com/tc39/proposal-rm-builtin-subclassing. |
per @bakkot, moved my comments here: tc39/proposal-rm-builtin-subclassing#20 |
This comment has been minimized.
This comment has been minimized.
Closing as done in tc39/how-we-work#157 (which isn't merged yet but we've at least decided what we're doing, which is what @domenic suggested above). |
In light of the committee's decision to reject #1289, and the upcoming set methods proposal (which would be one of the first usages of
Symbol.species
in the spec which worked for methods invoked on non-subclasses) it would be valuable for the committee to decide what our rationale forSymbol.species
is. In particular:Symbol.species
is used, going forward?I've suggested some options below. Please react with 👍 and 👎 to indicate your preferences, and suggest other alternatives if you have any.
cc @wycats @gsathya
The text was updated successfully, but these errors were encountered: