-
Notifications
You must be signed in to change notification settings - Fork 17
Subclassing #58
Comments
The current algorithm has no [UC] interleaving after the generic portion — it initializes [[MapData]] unobservably. That seems pretty valuable given we can trivially shadow |
Even |
The committee hasn’t seemed interested in furthering those patterns on any new methods. The Promise statics were this way solely to remain consistent with Promise.all and race (and fromAsync with from). I would expect that withResolvers - which is not stage 3 and thus nowhere near complete - will in fact have this proposal’s semantics. When subclassing anything, you have no guarantees methods will “just work”, and there’s nothing wrong with reimplementing it on a subclass yourself. |
See (brief) discussion here as well as earlier on Matrix (and the next couple days after that link).
In reviewing subclasses of I think this is pretty strong evidence that our attempts to add affordances for subclassing in the past have been too clever by half, and we should just let people write subclasses which customize behavior of methods by replacing those methods (you know, the normal way subclassing works), instead of trying to provide customization points. |
It's very sad that someone from the committee wanna kill good practices added in ES6 and throw the language back to the last millennium.
In this case - maybe, it was just a performance-related example.
However, a significant part of the Web has benefited from it. For example, patching those methods also fixes the constructor without patching it where it's not required. Or delegation to Personally, I can live without it - it's much simpler to use polyfill implementation instead of reuse of native features, however, users will suffer because of extra problems. |
@zloirock You can read more about the committee's opinions on subclassing built-ins in the 31 March 2022 notes and accompanying slides. tl;dr: Users shouldn't sub-class built-ins, they should wrap them instead. Use a public protocol for function arguments, but manipulate private fields (or internal slots) directly for the |
Closing as answered. |
Why?
Object
always was a special case, more other,Object.groupBy
should create an object withnull
prototype. ButMap
... Unlike some new instance methods where TC39 decided to break subclassing, new static methods use proper subclassing and create new instances fromthis
.Promise.any
,Array.fromAsync
,Promise.withResolvers
, etc...The text was updated successfully, but these errors were encountered: