Closed benlesh closed 7 years ago
When we're in a browser that has a native property - like certain versions of Firefox with "@@iterator"
- we use that. However, when we're not in a browser that has that, or Symbol
, there's no global place to put it.
Where would you suggest?
Note that the "strange workaround" you're using is actually the perfect and correct approach to reliably get this value - I'm not sure why you'd need a different one.
Note that the "strange workaround" you're using is actually the perfect and correct approach to reliably get this value - I'm not sure why you'd need a different one.
If you ever change your implementation of Map
or Set
, such that Map.prototype[$yourIterator$] !== Map.prototype.entries
, then the workaround breaks.
@blesh if we did that, we'd be violating the spec - thus, we will never do that.
To clarify, the spec requires that Map.prototype[Symbol.iterator] === Map.prototype.entries && Set.prototype[Symbol.iterator] === Set.prototype.values && Array.prototype[Symbol.iterator] === Array.prototype.values
be true
.
Interesting. Thanks. I couldn't locate the spec on this.
It's still unfortunate that we have a special case for es6-shim due to a somewhat avant-garde symbol property name. (@@iterator would have been nice)
Thanks for your feedback.
I explicitly chose not to use "@@iterator" to avoid people wrongly attempting to "polyfill" iterators based on Firefox's unfortunate choice to make a nonstandard string property magical.
I think we all would have been better off if people had just stuck to a few agreed upon conventions, honestly. But it's no big deal. It'll all be gone in a few years.
I love your optimism :-) the first browser that didn't need the es5-shim appeared within the last year, 6 years after ES5 was standard.
Haha... Aw, 6 years isn't a big deal. Look how long it took Java to get generics or arrow functions, and that's just one platform.
Currently this library uses a library-specific string for iterators if Symbol.iterator does not exist.
This has meant we need a strange workaround for RxJS to access iterators on types provided by es6-shim. This isn't ideal, because if you change your implementation of
Set
orMap
, our workaround will break.There are two fixes I'll propose for this, and neither are perfect:
"@@iterator"
.$iterator$
variable you're using somewhere globally so other libraries like RxJS can check for it and use it without workarounds.