Actually, Map is something I've missed several times lately when both Object and Array have fallen short. Set would also be useful. Having become used to the two in NodeJS, it's hard to live without them in Espruino :)
Arguments for adding Map:
Until Map arrived, JavaScript lacked a "pure" associative array. Instead, Object is often used/misused, leading to complicated code and weird issues, mainly due to its prototype nature and its limitation of only strings as keys.
With Map, keys can be of any type, they're easily iterated (in insertion order), and it's easy to get a map's size or check if it has a certain key. It performs better, and it just works! After years of trying to make Object behave like an associative array, it's like a breath of fresh air.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Actually,
Map
is something I've missed several times lately when bothObject
andArray
have fallen short.Set
would also be useful. Having become used to the two in NodeJS, it's hard to live without them in Espruino :)Arguments for adding
Map
:Until
Map
arrived, JavaScript lacked a "pure" associative array. Instead,Object
is often used/misused, leading to complicated code and weird issues, mainly due to its prototype nature and its limitation of only strings as keys.With
Map
, keys can be of any type, they're easily iterated (in insertion order), and it's easy to get a map's size or check if it has a certain key. It performs better, and it just works! After years of trying to makeObject
behave like an associative array, it's like a breath of fresh air.Shouldn't be too hard to implement, should it? :)