Where are Map entries stored?

50 views Asked by At

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?

1

There are 1 answers

0
Bergi On BEST ANSWER

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.