20.1 Object Objects
20.1.1 The Object Constructor
The Object
- is %Object%.
- is the initial value of the
"Object" property of theglobal object . - creates a new
ordinary object when called as aconstructor . - performs a type conversion when called as a function rather than as a
constructor . - may be used as the value of an
extends
clause of a class definition.
20.1.1.1 Object ( [ value ] )
This function performs the following steps when called:
- If NewTarget is neither
undefined nor theactive function object , then- Return ?
OrdinaryCreateFromConstructor (NewTarget,"%Object.prototype%" ).
- Return ?
- If value is either
undefined ornull , returnOrdinaryObjectCreate (%Object.prototype% ). - Return !
ToObject (value).
20.1.2 Properties of the Object Constructor
The Object
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has a
"length" property whose value is1 𝔽. - has the following additional properties:
20.1.2.1 Object.assign ( target, ...sources )
This function copies the values of all of the enumerable own properties from one or more source objects to a target object.
It performs the following steps when called:
The
20.1.2.2 Object.create ( O, Properties )
This function creates a new object with a specified prototype.
It performs the following steps when called:
- If O
is not an Object and O is notnull , throw aTypeError exception. - Let obj be
OrdinaryObjectCreate (O). - If Properties is not
undefined , then- Return ?
ObjectDefineProperties (obj, Properties).
- Return ?
- Return obj.
20.1.2.3 Object.defineProperties ( O, Properties )
This function adds own properties and/or updates the attributes of existing own properties of an object.
It performs the following steps when called:
- If O
is not an Object , throw aTypeError exception. - Return ?
ObjectDefineProperties (O, Properties).
20.1.2.3.1 ObjectDefineProperties ( O, Properties )
The abstract operation ObjectDefineProperties takes arguments O (an Object) and Properties (an
- Let props be ?
ToObject (Properties). - Let keys be ? props.[[OwnPropertyKeys]]().
- Let descriptors be a new empty
List . - For each element nextKey of keys, do
- Let propDesc be ? props.[[GetOwnProperty]](nextKey).
- If propDesc is not
undefined and propDesc.[[Enumerable]] istrue , then- Let descObj be ?
Get (props, nextKey). - Let desc be ?
ToPropertyDescriptor (descObj). - Append the
Record { [[Key]]: nextKey, [[Descriptor]]: desc } to descriptors.
- Let descObj be ?
- For each element property of descriptors, do
- Perform ?
DefinePropertyOrThrow (O, property.[[Key]], property.[[Descriptor]]).
- Perform ?
- Return O.
20.1.2.4 Object.defineProperty ( O, P, Attributes )
This function adds an own property and/or updates the attributes of an existing own property of an object.
It performs the following steps when called:
- If O
is not an Object , throw aTypeError exception. - Let key be ?
ToPropertyKey (P). - Let desc be ?
ToPropertyDescriptor (Attributes). - Perform ?
DefinePropertyOrThrow (O, key, desc). - Return O.
20.1.2.5 Object.entries ( O )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let entryList be ?
EnumerableOwnProperties (obj,key+value ). - Return
CreateArrayFromList (entryList).
20.1.2.6 Object.freeze ( O )
This function performs the following steps when called:
- If O
is not an Object , return O. - Let status be ?
SetIntegrityLevel (O,frozen ). - If status is
false , throw aTypeError exception. - Return O.
20.1.2.7 Object.fromEntries ( iterable )
This function performs the following steps when called:
- Perform ?
RequireObjectCoercible (iterable). - Let obj be
OrdinaryObjectCreate (%Object.prototype% ). Assert : obj is an extensibleordinary object with no own properties.- Let closure be a new
Abstract Closure with parameters (key, value) that captures obj and performs the following steps when called:- Let propertyKey be ?
ToPropertyKey (key). - Perform !
CreateDataPropertyOrThrow (obj, propertyKey, value). - Return
undefined .
- Let propertyKey be ?
- Let adder be
CreateBuiltinFunction (closure, 2,"" , « »). - Return ?
AddEntriesFromIterable (obj, iterable, adder).
20.1.2.8 Object.getOwnPropertyDescriptor ( O, P )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let key be ?
ToPropertyKey (P). - Let desc be ? obj.[[GetOwnProperty]](key).
- Return
FromPropertyDescriptor (desc).
20.1.2.9 Object.getOwnPropertyDescriptors ( O )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let ownKeys be ? obj.[[OwnPropertyKeys]]().
- Let descriptors be
OrdinaryObjectCreate (%Object.prototype% ). - For each element key of ownKeys, do
- Let desc be ? obj.[[GetOwnProperty]](key).
- Let descriptor be
FromPropertyDescriptor (desc). - If descriptor is not
undefined , perform !CreateDataPropertyOrThrow (descriptors, key, descriptor).
- Return descriptors.
20.1.2.10 Object.getOwnPropertyNames ( O )
This function performs the following steps when called:
- Return
CreateArrayFromList (?GetOwnPropertyKeys (O,string )).
20.1.2.11 Object.getOwnPropertySymbols ( O )
This function performs the following steps when called:
- Return
CreateArrayFromList (?GetOwnPropertyKeys (O,symbol )).
20.1.2.11.1 GetOwnPropertyKeys ( O, type )
The abstract operation GetOwnPropertyKeys takes arguments O (an
- Let obj be ?
ToObject (O). - Let keys be ? obj.[[OwnPropertyKeys]]().
- Let nameList be a new empty
List . - For each element nextKey of keys, do
- If nextKey
is a Symbol and type issymbol , or if nextKeyis a String and type isstring , then- Append nextKey to nameList.
- If nextKey
- Return nameList.
20.1.2.12 Object.getPrototypeOf ( O )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Return ? obj.[[GetPrototypeOf]]().
20.1.2.13 Object.groupBy ( items, callbackfn )
callbackfn should be a function that accepts two arguments. groupBy
calls callbackfn once for each element in items, in ascending order, and constructs a new object. Each value returned by callbackfn is coerced to a
callbackfn is called with two arguments: the value of the element and the index of the element.
The return value of groupBy
is an object that does not inherit from
This function performs the following steps when called:
- Let groups be ?
GroupBy (items, callbackfn,property ). - Let obj be
OrdinaryObjectCreate (null ). - For each
Record { [[Key]], [[Elements]] } g of groups, do- Let elements be
CreateArrayFromList (g.[[Elements]]). - Perform !
CreateDataPropertyOrThrow (obj, g.[[Key]], elements).
- Let elements be
- Return obj.
20.1.2.14 Object.hasOwn ( O, P )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let key be ?
ToPropertyKey (P). - Return ?
HasOwnProperty (obj, key).
20.1.2.15 Object.is ( value1, value2 )
This function performs the following steps when called:
- Return
SameValue (value1, value2).
20.1.2.16 Object.isExtensible ( O )
This function performs the following steps when called:
- If O
is not an Object , returnfalse . - Return ?
IsExtensible (O).
20.1.2.17 Object.isFrozen ( O )
This function performs the following steps when called:
- If O
is not an Object , returntrue . - Return ?
TestIntegrityLevel (O,frozen ).
20.1.2.18 Object.isSealed ( O )
This function performs the following steps when called:
- If O
is not an Object , returntrue . - Return ?
TestIntegrityLevel (O,sealed ).
20.1.2.19 Object.keys ( O )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let keyList be ?
EnumerableOwnProperties (obj,key ). - Return
CreateArrayFromList (keyList).
20.1.2.20 Object.preventExtensions ( O )
This function performs the following steps when called:
- If O
is not an Object , return O. - Let status be ? O.[[PreventExtensions]]().
- If status is
false , throw aTypeError exception. - Return O.
20.1.2.21 Object.prototype
The initial value of Object.prototype
is the
This property has the attributes { [[Writable]]:
20.1.2.22 Object.seal ( O )
This function performs the following steps when called:
- If O
is not an Object , return O. - Let status be ?
SetIntegrityLevel (O,sealed ). - If status is
false , throw aTypeError exception. - Return O.
20.1.2.23 Object.setPrototypeOf ( O, proto )
This function performs the following steps when called:
- Set O to ?
RequireObjectCoercible (O). - If proto
is not an Object and proto is notnull , throw aTypeError exception. - If O
is not an Object , return O. - Let status be ? O.[[SetPrototypeOf]](proto).
- If status is
false , throw aTypeError exception. - Return O.
20.1.2.24 Object.values ( O )
This function performs the following steps when called:
- Let obj be ?
ToObject (O). - Let valueList be ?
EnumerableOwnProperties (obj,value ). - Return
CreateArrayFromList (valueList).
20.1.3 Properties of the Object Prototype Object
The Object prototype object:
- is %Object.prototype%.
- has an [[Extensible]] internal slot whose value is
true . - has the internal methods defined for
ordinary objects , except for the [[SetPrototypeOf]] method, which is as defined in10.4.7.1 . (Thus, it is animmutable prototype exotic object .) - has a [[Prototype]] internal slot whose value is
null .
20.1.3.1 Object.prototype.constructor
The initial value of Object.prototype.constructor
is
20.1.3.2 Object.prototype.hasOwnProperty ( V )
This method performs the following steps when called:
- Let P be ?
ToPropertyKey (V). - Let O be ?
ToObject (this value). - Return ?
HasOwnProperty (O, P).
20.1.3.3 Object.prototype.isPrototypeOf ( V )
This method performs the following steps when called:
- If V
is not an Object , returnfalse . - Let O be ?
ToObject (this value). - Repeat,
- Set V to ? V.[[GetPrototypeOf]]().
- If V is
null , returnfalse . - If
SameValue (O, V) istrue , returntrue .
20.1.3.4 Object.prototype.propertyIsEnumerable ( V )
This method performs the following steps when called:
- Let P be ?
ToPropertyKey (V). - Let O be ?
ToObject (this value). - Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returnfalse . - Return desc.[[Enumerable]].
This method does not consider objects in the prototype chain.
20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
This method performs the following steps when called:
- Let O be the
this value. - Return ?
Invoke (O,"toString" ).
The optional parameters to this method are not used but are intended to correspond to the parameter pattern used by ECMA-402 toLocaleString
methods. Implementations that do not include ECMA-402 support must not use those parameter positions for other purposes.
This method provides a generic toLocaleString
implementation for objects that have no locale-sensitive toString
behaviour. Array
, Number
, Date
, and toLocaleString
methods.
ECMA-402 intentionally does not provide an alternative to this default implementation.
20.1.3.6 Object.prototype.toString ( )
This method performs the following steps when called:
- If the
this value isundefined , return"[object Undefined]" . - If the
this value isnull , return"[object Null]" . - Let O be !
ToObject (this value). - Let isArray be ?
IsArray (O). - If isArray is
true , let builtinTag be"Array" . - Else if O has a [[ParameterMap]] internal slot, let builtinTag be
"Arguments" . - Else if O has a [[Call]] internal method, let builtinTag be
"Function" . - Else if O has an [[ErrorData]] internal slot, let builtinTag be
"Error" . - Else if O has a [[BooleanData]] internal slot, let builtinTag be
"Boolean" . - Else if O has a [[NumberData]] internal slot, let builtinTag be
"Number" . - Else if O has a [[StringData]] internal slot, let builtinTag be
"String" . - Else if O has a [[DateValue]] internal slot, let builtinTag be
"Date" . - Else if O has a [[RegExpMatcher]] internal slot, let builtinTag be
"RegExp" . - Else, let builtinTag be
"Object" . - Let tag be ?
Get (O,@@toStringTag ). - If tag
is not a String , set tag to builtinTag. - Return the
string-concatenation of"[object " , tag, and"]" .
Historically, this method was occasionally used to access the String value of the [[Class]] internal slot that was used in previous editions of this specification as a nominal type tag for various built-in objects. The above definition of toString
preserves compatibility for legacy code that uses toString
as a test for those specific kinds of built-in objects. It does not provide a reliable type testing mechanism for other kinds of built-in or program defined objects. In addition, programs can use
20.1.3.7 Object.prototype.valueOf ( )
This method performs the following steps when called:
- Return ?
ToObject (this value).
20.1.3.8 Object.prototype.__proto__
Object.prototype.__proto__
is an
20.1.3.8.1 get Object.prototype.__proto__
The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps when called:
- Let O be ?
ToObject (this value). - Return ? O.[[GetPrototypeOf]]().
20.1.3.8.2 set Object.prototype.__proto__
The value of the [[Set]] attribute is a built-in function that takes an argument proto. It performs the following steps when called:
- Let O be ?
RequireObjectCoercible (this value). - If proto
is not an Object and proto is notnull , returnundefined . - If O
is not an Object , returnundefined . - Let status be ? O.[[SetPrototypeOf]](proto).
- If status is
false , throw aTypeError exception. - Return
undefined .
20.1.3.9 Legacy Object.prototype Accessor Methods
20.1.3.9.1 Object.prototype.__defineGetter__ ( P, getter )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - If
IsCallable (getter) isfalse , throw aTypeError exception. - Let desc be PropertyDescriptor { [[Get]]: getter, [[Enumerable]]:
true , [[Configurable]]:true }. - Let key be ?
ToPropertyKey (P). - Perform ?
DefinePropertyOrThrow (O, key, desc). - Return
undefined .
20.1.3.9.2 Object.prototype.__defineSetter__ ( P, setter )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - If
IsCallable (setter) isfalse , throw aTypeError exception. - Let desc be PropertyDescriptor { [[Set]]: setter, [[Enumerable]]:
true , [[Configurable]]:true }. - Let key be ?
ToPropertyKey (P). - Perform ?
DefinePropertyOrThrow (O, key, desc). - Return
undefined .
20.1.3.9.3 Object.prototype.__lookupGetter__ ( P )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let key be ?
ToPropertyKey (P). - Repeat,
- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined , then- If
IsAccessorDescriptor (desc) istrue , return desc.[[Get]]. - Return
undefined .
- If
- Set O to ? O.[[GetPrototypeOf]]().
- If O is
null , returnundefined .
20.1.3.9.4 Object.prototype.__lookupSetter__ ( P )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let key be ?
ToPropertyKey (P). - Repeat,
- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined , then- If
IsAccessorDescriptor (desc) istrue , return desc.[[Set]]. - Return
undefined .
- If
- Set O to ? O.[[GetPrototypeOf]]().
- If O is
null , returnundefined .
20.1.4 Properties of Object Instances
Object instances have no special properties beyond those inherited from the