Polyfill for Maps and Sets

Kris Kowal kris.kowal at cixar.com
Thu Jan 17 11:07:47 PST 2013


It is a good point that the specified keys(), values(), and items()
return iterators rather than arrays, which makes them a little less
friendly from a shimming perspective.

http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets

I made a few opinionated deviations from spec in Montage’s Collections package.

https://github.com/montagejs/collections

I went with iterate() instead of iterator(). I feel the tide rolling
over me on that one and will probably back off.

keys(), values(), and items() return arrays. I didn’t even realize
this was against the spec. I would have expected iterateKeys(),
iterateValues(), and iterateItems() to return iterators and keys(),
values(), and items() to return Array snapshots.

That said, I would also expect the Iterator prototype to be pretty
rich, so this would work regardless of whether keys() returns an Array
or Iterator. In either case, it is straightforward to shim.

map.keys().forEach(function () {
});

Kris Kowal


More information about the es-discuss mailing list