Search code examples
javascriptdictionaryes6-map

Where are Map entries stored?


If I try to create a Map without calling the constructor, the object is unusable:

const map = Object.create(Map.prototype);
map.entries();

Out of curiosity, I wondered where the entries were stored but the constructor does not seem to add properties:

const map = new Map;
console.log(Object.getPrototypeOf(map) === Map.prototype);
console.log(Object.getOwnPropertyDescriptors(map));

Any idea?


Solution

  • They're stored in an internal slot of the object, which only gets created when you call new Map. It's an implementation detail of the native collections. You can only access entries through the native methods.