2

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?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
user3515941
  • 141
  • 1
  • 8
  • Why does it really matter? It's going to be an implementation detail. This might not even be visible from within JS. – VLAZ Nov 11 '20 at 11:07

1 Answers1

1

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375