Map native properties

Map usually uses .get()/.set()/.delete()/.has(), but it'd be nice if Map pairs were accessed as regular ECMAScript properties, noting the following:

  • When reading/writting a property on Map, it is a pair access.
  • When calling a property on Map with a String key, it is a call of a Map.prototype method.
  • For Function pairs to be called, you have to do [object Map].call("f", ...rest).

This would require .size to be .size() or .length() (similiar to the legacy E4X feature).

This idea is borrowed from the E4X XML/XMLList proposal. Originally I think ECMAScript 4 was also going to support Map.<K, V> with similiar semantics.


And now it's too late for this change. The only hope is if there is a directive like "use strict"; to change it, but it's complicated...

Also the object model does not differentiate between a property read (o.p) and a method call (o.p()).

2 Likes

That's something that would have been possible prior to ES6/ES2015, but is now permanently impossible (as of over a decade ago)

2 Likes