How Value To __proto__ Is Assigned In Javascript?
Solution 1:
Full details in the specification*, but when you use a constructor function with null
for its prototype
property, new
assigns Object.prototype
(well, the default prototype for the realm; Object.prototype
for our purposes) as the prototype of the new object.
I believe the only way to create an object with no prototype is Object.create(null)
.
You can set the prototype to null
after creating the object via Object.setPrototypeOf
, but in general it's best to avoid changing an object's prototype after you've created it.
* Specifically, it's tucked away in GetPrototypeFromConstructor
, which says if the type of the constructor's prototype
property isn't Object (for this purpose, null
is of type Null, not type Object), use the default prototype for the realm.
Post a Comment for "How Value To __proto__ Is Assigned In Javascript?"