Object.create
generates a fresh standard object that inherits from the provided argument without any initialization, such as invoking the constructor.
For Set
and Map
, it is crucial to call the constructor because it establishes the necessary internal slots needed for the collection to operate (specifically, to store elements). These internal slots must be created alongside the object and cannot be added later on. This can only be achieved by using the constructor with the new
keyword.
By utilizing Object.create
, objects inherit has
and get
methods from their respective prototype objects smoothly. However, when these methods are called, the receiver (this
value) is the standard object lacking the essential internal slots that would make it a true Set
or Map
, resulting in exceptions being thrown.