You are reading a single comment by @Joakim and its replies. Click here to read the full conversation.
  • Shouldn't be too hard to implement, should it? :)

    Here you go :)

    Would it not be possible to write Map and Set as a JavaScript module though? I'm not sure they actually require interpreter support.

  • Shouldn't be too hard to implement, should it? :)

    Here you go :)

    Now I regret saying that :) It came off wrong, sorry if it sounded like writing features for Espruino is easy! I'm sure it would take many hours to implement this, and I know you're not getting paid by the hour to work on Espruino. Instead I should thank you for making and continuously improving Espruino for free, and for providing such great support!

    I looked around for JS polyfills for Map and Set, and found one that was used by Firefox Nightly and Chrome Dev when the features were under the Enable Experimental JavaScript flag. It's also the smallest that I found (6KB, 2.77KB minified) and claims to have good performance.­lections­lection/es6-collections/master/index.js

    As far as I can tell, it actually does roughly what your bodged up implementation does :)

    I tested it on a Pico (had to move the exported functions to the bottom) and it seems to work fine, except for two issues:

    • Although it shims iterators, Espruino doesn't support iterators or for…of (good point!)
    • The .size property is missing (requires support for getters in Object.defineProperty)­82b3cce32092cccfb99701d

    Despite those issues, I'll give it a try on a project I'm working on later and see how it goes.


Avatar for Joakim @Joakim started