SpeciesConstructor(o, %Set) vs. %Set%

# Michał Wadas (6 months ago)

This is question directed more to TC39 members. I'm updating Set methods proposal right now and I don't understand when SpeciesConstructor should be used and when I should just hardcode %Set%.

Michał Wadas

# Jordan Harband (6 months ago)

My sense is that any time you want to enable subclassing, you'd use SpeciesConstructor - are there specific cases where you're seeing it not be used?

# Kevin Gibbons (6 months ago)

That is an excellent question; see tc39/ecma262#1313 . I would lean towards using SpeciesConstructor because it is consistent with the language as currently defined, and we have not gotten consensus to decide on a different design.

It's pretty unfortunate because it seems likely that very few people will ever benefit from subclassing Set but every visitor of every webpage which uses one of these methods during first load will have to pay the price of several observable property lookups, but what can you do. That's already true for anyone using .map on an array or .then on a promise.