Don't create your own Map class/global in javascript

By David
7th April 2022

In my Domain of the Ancients javascript game I have a class (which, of course, is therefore a global variable) called Map to represent the game map. As it turns out that's a bad idea! There's a perfectly good global object in javascript already called Map and so, of course, my definition ended up replacing that one. As it happens I don't use that object (at least not at the time of writing), but node.js does and it will break12. As my unit tests in my build process use node.js for my unit testing my unit tests broke3. Anyway, to cut the story short, I've renamed my Map class to GameMap.


  1. At least on linux it does
  2. The error message, for reference is TypeError: cache.get is not a function
  3. or, more accurately they broke on Linux. Quite why the unit tests worked on windows is an interesting question I can't answer!