19 Fundamental Objects
19.1 Object Objects
19.1.1 The Object Constructor
The Object
- is the intrinsic object
%Object% . - is the initial value of the
Objectproperty of theglobal object . - creates a new ordinary object when called as a
constructor . - performs a
type conversion when called as a function rather than as aconstructor . - is designed to be subclassable. It may be used as the value of an
extendsclause of a class definition.
19.1.1.1 Object ( [ value ] )
When Object function is called with optional argument value, the following steps are taken:
- If NewTarget is neither
undefined nor the active function, then- Return ?
OrdinaryCreateFromConstructor (NewTarget,"%ObjectPrototype%").
- Return ?
- If value is
null ,undefined or not supplied, returnObjectCreate (%ObjectPrototype% ). - Return !
ToObject (value).
The length property of the Object
19.1.2 Properties of the Object Constructor
The Object
- has a [[Prototype]] internal slot whose value is the intrinsic object
%FunctionPrototype% . - has a
lengthproperty. - has the following additional properties:
19.1.2.1 Object.assign ( target, ...sources )
The assign function is used to copy the values of all of the enumerable own properties from one or more source objects to a target object. When the assign function is called, the following steps are taken:
- Let to be ?
ToObject (target). - If only one argument was passed, return to.
- Let sources be the
List of argument values starting with the second argument. - For each element nextSource of sources, in ascending index order, do
- Return to.
The length property of the assign function is 2.
19.1.2.2 Object.create ( O, Properties )
The create function creates a new object with a specified prototype. When the create function is called, the following steps are taken:
- If
Type (O) is neither Object nor Null, throw aTypeError exception. - Let obj be
ObjectCreate (O). - If Properties is not
undefined , then- Return ?
ObjectDefineProperties (obj, Properties).
- Return ?
- Return obj.
19.1.2.3 Object.defineProperties ( O, Properties )
The defineProperties function is used to add own properties and/or update the attributes of existing own properties of an object. When the defineProperties function is called, the following steps are taken:
- Return ?
ObjectDefineProperties (O, Properties).
19.1.2.3.1 Runtime Semantics: ObjectDefineProperties ( O, Properties )
The abstract operation ObjectDefineProperties with arguments O and Properties performs the following steps:
- If
Type (O) is not Object, throw aTypeError exception. - Let props be ?
ToObject (Properties). - Let keys be ? props.[[OwnPropertyKeys]]().
- Let descriptors be a new empty
List . - For each element nextKey of keys in
List order, 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 pair (a two element
List ) consisting of nextKey and desc to the end of descriptors.
- Let descObj be ?
- For each pair from descriptors in list order, do
- Let P be the first element of pair.
- Let desc be the second element of pair.
- Perform ?
DefinePropertyOrThrow (O, P, desc).
- Return O.
19.1.2.4 Object.defineProperty ( O, P, Attributes )
The defineProperty function is used to add an own property and/or update the attributes of an existing own property of an object. When the defineProperty function is called, the following steps are taken:
- If
Type (O) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (P). - Let desc be ?
ToPropertyDescriptor (Attributes). - Perform ?
DefinePropertyOrThrow (O, key, desc). - Return O.
19.1.2.5 Object.entries ( O )
When the entries function is called with argument O, the following steps are taken:
- Let obj be ?
ToObject (O). - Let nameList be ?
EnumerableOwnPropertyNames (obj,"key+value" ). - Return
CreateArrayFromList (nameList).
19.1.2.6 Object.freeze ( O )
When the freeze function is called, the following steps are taken:
- If
Type (O) is not Object, return O. - Let status be ?
SetIntegrityLevel (O,"frozen"). - If status is
false , throw aTypeError exception. - Return O.
19.1.2.7 Object.getOwnPropertyDescriptor ( O, P )
When the getOwnPropertyDescriptor function is called, the following steps are taken:
- Let obj be ?
ToObject (O). - Let key be ?
ToPropertyKey (P). - Let desc be ? obj.[[GetOwnProperty]](key).
- Return
FromPropertyDescriptor (desc).
19.1.2.8 Object.getOwnPropertyDescriptors ( O )
When the getOwnPropertyDescriptors function is called, the following steps are taken:
- Let obj be ?
ToObject (O). - Let ownKeys be ? obj.[[OwnPropertyKeys]]().
- Let descriptors be !
ObjectCreate (%ObjectPrototype% ). - For each element key of ownKeys in
List order, do- Let desc be ? obj.[[GetOwnProperty]](key).
- Let descriptor be !
FromPropertyDescriptor (desc). - If descriptor is not
undefined , perform !CreateDataProperty (descriptors, key, descriptor).
- Return descriptors.
19.1.2.9 Object.getOwnPropertyNames ( O )
When the getOwnPropertyNames function is called, the following steps are taken:
- Return ?
GetOwnPropertyKeys (O, String).
19.1.2.10 Object.getOwnPropertySymbols ( O )
When the getOwnPropertySymbols function is called with argument O, the following steps are taken:
- Return ?
GetOwnPropertyKeys (O, Symbol).
19.1.2.10.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type )
The abstract operation GetOwnPropertyKeys is called with arguments O and Type where O is an Object and Type is one of the ECMAScript specification types String or Symbol. The following steps are taken:
- Let obj be ?
ToObject (O). - Let keys be ? obj.[[OwnPropertyKeys]]().
- Let nameList be a new empty
List . - For each element nextKey of keys in
List order, do- If
Type (nextKey) is Type, then- Append nextKey as the last element of nameList.
- If
- Return
CreateArrayFromList (nameList).
19.1.2.11 Object.getPrototypeOf ( O )
When the getPrototypeOf function is called with argument O, the following steps are taken:
- Let obj be ?
ToObject (O). - Return ? obj.[[GetPrototypeOf]]().
19.1.2.12 Object.is ( value1, value2 )
When the is function is called with arguments value1 and value2, the following steps are taken:
- Return
SameValue (value1, value2).
19.1.2.13 Object.isExtensible ( O )
When the isExtensible function is called with argument O, the following steps are taken:
- If
Type (O) is not Object, returnfalse . - Return ?
IsExtensible (O).
19.1.2.14 Object.isFrozen ( O )
When the isFrozen function is called with argument O, the following steps are taken:
- If
Type (O) is not Object, returntrue . - Return ?
TestIntegrityLevel (O,"frozen").
19.1.2.15 Object.isSealed ( O )
When the isSealed function is called with argument O, the following steps are taken:
- If
Type (O) is not Object, returntrue . - Return ?
TestIntegrityLevel (O,"sealed").
19.1.2.16 Object.keys ( O )
When the keys function is called with argument O, the following steps are taken:
- Let obj be ?
ToObject (O). - Let nameList be ?
EnumerableOwnPropertyNames (obj,"key" ). - Return
CreateArrayFromList (nameList).
19.1.2.17 Object.preventExtensions ( O )
When the preventExtensions function is called, the following steps are taken:
- If
Type (O) is not Object, return O. - Let status be ? O.[[PreventExtensions]]().
- If status is
false , throw aTypeError exception. - Return O.
19.1.2.18 Object.prototype
The initial value of Object.prototype is the intrinsic object
This property has the attributes { [[Writable]]:
19.1.2.19 Object.seal ( O )
When the seal function is called, the following steps are taken:
- If
Type (O) is not Object, return O. - Let status be ?
SetIntegrityLevel (O,"sealed"). - If status is
false , throw aTypeError exception. - Return O.
19.1.2.20 Object.setPrototypeOf ( O, proto )
When the setPrototypeOf function is called with arguments O and proto, the following steps are taken:
- Let O be ?
RequireObjectCoercible (O). - If
Type (proto) is neither Object nor Null, throw aTypeError exception. - If
Type (O) is not Object, return O. - Let status be ? O.[[SetPrototypeOf]](proto).
- If status is
false , throw aTypeError exception. - Return O.
19.1.2.21 Object.values ( O )
When the values function is called with argument O, the following steps are taken:
- Let obj be ?
ToObject (O). - Let nameList be ?
EnumerableOwnPropertyNames (obj,"value" ). - Return
CreateArrayFromList (nameList).
19.1.3 Properties of the Object Prototype Object
The Object prototype object:
- is the intrinsic object
%ObjectPrototype% . - is an
immutable prototype exotic object . - has a [[Prototype]] internal slot whose value is
null .
19.1.3.1 Object.prototype.constructor
The initial value of Object.prototype.constructor is the intrinsic object
19.1.3.2 Object.prototype.hasOwnProperty ( V )
When the hasOwnProperty method is called with argument V, the following steps are taken:
- Let P be ?
ToPropertyKey (V). - Let O be ?
ToObject (this value). - Return ?
HasOwnProperty (O, P).
The ordering of steps 1 and 2 is chosen to ensure that any exception that would have been thrown by step 1 in previous editions of this specification will continue to be thrown even if the
19.1.3.3 Object.prototype.isPrototypeOf ( V )
When the isPrototypeOf method is called with argument V, the following steps are taken:
The ordering of steps 1 and 2 preserves the behaviour specified by previous editions of this specification for the case where V is not an object and the
19.1.3.4 Object.prototype.propertyIsEnumerable ( V )
When the propertyIsEnumerable method is called with argument V, the following steps are taken:
- 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.
The ordering of steps 1 and 2 is chosen to ensure that any exception that would have been thrown by step 1 in previous editions of this specification will continue to be thrown even if the
19.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
When the toLocaleString method is called, the following steps are taken:
- Let O be the
this value. - Return ?
Invoke (O,"toString").
The optional parameters to this function are not used but are intended to correspond to the parameter pattern used by ECMA-402 toLocaleString functions. Implementations that do not include ECMA-402 support must not use those parameter positions for other purposes.
This function provides a generic toLocaleString implementation for objects that have no locale-specific toString behaviour. Array, Number, Date, and Typed Arrays provide their own locale-sensitive toLocaleString methods.
ECMA-402 intentionally does not provide an alternative to this default implementation.
19.1.3.6 Object.prototype.toString ( )
When the toString method is called, the following steps are taken:
- 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 is a String
exotic object , let builtinTag be"String". - 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 [[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
Type (tag) is not String, let tag be builtinTag. - Return the
string-concatenation of"[object ", tag, and"]".
This function is the %ObjProto_toString% intrinsic object.
Historically, this function 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 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
19.1.3.7 Object.prototype.valueOf ( )
When the valueOf method is called, the following steps are taken:
- Return ?
ToObject (this value).
This function is the %ObjProto_valueOf% intrinsic object.
19.1.4 Properties of Object Instances
Object instances have no special properties beyond those inherited from the Object prototype object.
19.2 Function Objects
19.2.1 The Function Constructor
The Function
- is the intrinsic object
%Function% . - is the initial value of the
Functionproperty of theglobal object . - creates and initializes a new
function object when called as a function rather than as aconstructor . Thus the function callFunction(…)is equivalent to the object creation expressionnew Function(…)with the same arguments. - is designed to be subclassable. It may be used as the value of an
extendsclause of a class definition. Subclass constructors that intend to inherit the specifiedFunctionbehaviour must include asupercall to theFunctionconstructor to create and initialize a subclass instance with the internal slots necessary for built-in function behaviour. All ECMAScript syntactic forms for defining function objects create instances ofFunction. There is no syntactic means to create instances ofFunctionsubclasses except for the built-inGeneratorFunction,AsyncFunction, andAsyncGeneratorFunctionsubclasses.
19.2.1.1 Function ( p1, p2, … , pn, body )
The last argument specifies the body (executable code) of a function; any preceding arguments specify formal parameters.
When the Function function is called with some arguments p1, p2, … , pn, body (where n might be 0, that is, there are no “ p ” arguments, and where body might also not be provided), the following steps are taken:
- Let C be the
active function object . - Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]].
- Return ?
CreateDynamicFunction (C, NewTarget,"normal", args).
It is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the following expressions produce the same result:
new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a,b", "c", "return a+b+c")
19.2.1.1.1 Runtime Semantics: CreateDynamicFunction ( constructor, newTarget, kind, args )
The abstract operation CreateDynamicFunction is called with arguments constructor, newTarget, kind, and args. constructor is the new was initially applied to, kind is either "normal", "generator", "async", or "async generator", and args is a
Assert : Theexecution context stack has at least two elements.- Let callerContext be the second to top element of the
execution context stack . - Let callerRealm be callerContext's
Realm . - Let calleeRealm be
the current Realm Record . - Perform ?
HostEnsureCanCompileStrings (callerRealm, calleeRealm). - If newTarget is
undefined , set newTarget to constructor. - If kind is
"normal", then- Let goal be the grammar symbol
FunctionBody .[~Yield, ~ Await ] - Let parameterGoal be the grammar symbol
FormalParameters .[~Yield, ~ Await ] - Let fallbackProto be
"%FunctionPrototype%".
- Let goal be the grammar symbol
- Else if kind is
"generator", then- Let goal be the grammar symbol
GeneratorBody . - Let parameterGoal be the grammar symbol
FormalParameters .[+Yield, ~ Await ] - Let fallbackProto be
"%Generator%".
- Let goal be the grammar symbol
- Else if kind is
"async", thenAssert : kind is"async".- Let goal be the grammar symbol
AsyncFunctionBody . - Let parameterGoal be the grammar symbol
FormalParameters .[~Yield, + Await ] - Let fallbackProto be
"%AsyncFunctionPrototype%".
- Else,
Assert : kind is"async generator".- Let goal be the grammar symbol
AsyncGeneratorBody . - Let parameterGoal be the grammar symbol
FormalParameters .[+Yield, + Await ] - Let fallbackProto be
"%AsyncGenerator%".
- Let argCount be the number of elements in args.
- Let P be the empty String.
- If argCount = 0, let bodyText be the empty String.
- Else if argCount = 1, let bodyText be args[0].
- Else argCount > 1,
- Let firstArg be args[0].
Set P to ?ToString (firstArg).- Let k be 1.
- Repeat, while k < argCount-1
- Let nextArg be args[k].
- Let nextArgString be ?
ToString (nextArg). Set P to thestring-concatenation of the previous value of P,","(a comma), and nextArgString.- Increase k by 1.
- Let bodyText be args[k].
Set bodyText to ?ToString (bodyText).- Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text as described in
6.1.4 , using parameterGoal as thegoal symbol . Throw aSyntaxError exception if the parse fails. - Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text as described in
6.1.4 , using goal as thegoal symbol . Throw aSyntaxError exception if the parse fails. - Let strict be ContainsUseStrict of body.
- If any
static semantics errors are detected for parameters or body, throw aSyntaxError or aReferenceError exception, depending on thetype of the error. If strict istrue , the Early Error rules for are applied. Parsing andUniqueFormalParameters : FormalParameters early error detection may be interweaved in an implementation-dependent manner. - If strict is
true and IsSimpleParameterList of parameters isfalse , throw aSyntaxError exception. - If any element of the BoundNames of parameters also occurs in the LexicallyDeclaredNames of body, throw a
SyntaxError exception. - If body Contains
SuperCall istrue , throw aSyntaxError exception. - If parameters Contains
SuperCall istrue , throw aSyntaxError exception. - If body Contains
SuperProperty istrue , throw aSyntaxError exception. - If parameters Contains
SuperProperty istrue , throw aSyntaxError exception. - If kind is
"generator"or"async generator", then- If parameters Contains
YieldExpression istrue , throw aSyntaxError exception.
- If parameters Contains
- If kind is
"async"or"async generator", then- If parameters Contains
AwaitExpression istrue , throw aSyntaxError exception.
- If parameters Contains
- If strict is
true , then- If BoundNames of parameters contains any duplicate elements, throw a
SyntaxError exception.
- If BoundNames of parameters contains any duplicate elements, throw a
- Let proto be ?
GetPrototypeFromConstructor (newTarget, fallbackProto). - Let F be
FunctionAllocate (proto, strict, kind). - Let realmF be F.[[Realm]].
- Let scope be realmF.[[GlobalEnv]].
- Perform
FunctionInitialize (F,Normal , parameters, body, scope). - If kind is
"generator", then- Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }).
- Let prototype be
- Else if kind is
"async generator", then- Let prototype be
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }).
- Let prototype be
- Else if kind is
"normal", performMakeConstructor (F). - NOTE: Async functions are not constructable and do not have a [[Construct]] internal method or a
"prototype"property. - Perform
SetFunctionName (F,"anonymous"). - Return F.
A prototype property is created for every non-async function created using CreateDynamicFunction to provide for the possibility that the function will be used as a
19.2.2 Properties of the Function Constructor
The Function
- is itself a built-in
function object . - has a [[Prototype]] internal slot whose value is the intrinsic object
%FunctionPrototype% . - has the following properties:
19.2.2.1 Function.length
This is a
19.2.2.2 Function.prototype
The value of Function.prototype is
This property has the attributes { [[Writable]]:
19.2.3 Properties of the Function Prototype Object
The Function prototype object:
- is the intrinsic object
%FunctionPrototype% . - is itself a built-in
function object . - accepts any arguments and returns
undefined when invoked. - does not have a [[Construct]] internal method; it cannot be used as a
constructor with thenewoperator. - has a [[Prototype]] internal slot whose value is the intrinsic object
%ObjectPrototype% . - does not have a
prototypeproperty. - has a
lengthproperty whose value is 0. - has a
nameproperty whose value is the empty String.
The Function prototype object is specified to be a
19.2.3.1 Function.prototype.apply ( thisArg, argArray )
When the apply method is called on an object func with arguments thisArg and argArray, the following steps are taken:
- If
IsCallable (func) isfalse , throw aTypeError exception. - If argArray is
undefined ornull , then- Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg).
- Perform
- Let argList be ?
CreateListFromArrayLike (argArray). - Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg, argList).
The thisArg value is passed without modification as the
If func is an arrow function or a
19.2.3.2 Function.prototype.bind ( thisArg, ...args )
When the bind method is called with argument thisArg and zero or more args, it performs the following steps:
- Let Target be the
this value. - If
IsCallable (Target) isfalse , throw aTypeError exception. - Let args be a new (possibly empty)
List consisting of all of the argument values provided after thisArg in order. - Let F be ?
BoundFunctionCreate (Target, thisArg, args). - Let targetHasLength be ?
HasOwnProperty (Target,"length"). - If targetHasLength is
true , then - Else, let L be 0.
- Perform !
SetFunctionLength (F, L). - Let targetName be ?
Get (Target,"name"). - If
Type (targetName) is not String, let targetName be the empty string. - Perform
SetFunctionName (F, targetName,"bound"). - Return F.
Function objects created using Function.prototype.bind are exotic objects. They also do not have a prototype property.
If Target is an arrow function or a
19.2.3.3 Function.prototype.call ( thisArg, ...args )
When the call method is called on an object func with argument, thisArg and zero or more args, the following steps are taken:
- If
IsCallable (func) isfalse , throw aTypeError exception. - Let argList be a new empty
List . - If this method was called with more than one argument, then in left to right order, starting with the second argument, append each argument as the last element of argList.
- Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg, argList).
The thisArg value is passed without modification as the
If func is an arrow function or a
19.2.3.4 Function.prototype.constructor
The initial value of Function.prototype.constructor is the intrinsic object
19.2.3.5 Function.prototype.toString ( )
When the toString method is called on an object func, the following steps are taken:
- If func is a Bound Function
exotic object , then- Return an implementation-dependent String source code representation of func. The representation must conform to the rules below. It is implementation-dependent whether the representation includes
bound function information or information about the target function.
- Return an implementation-dependent String source code representation of func. The representation must conform to the rules below. It is implementation-dependent whether the representation includes
- If
Type (func) is Object and is either a built-infunction object or has an [[ECMAScriptCode]] internal slot, then- Return an implementation-dependent String source code representation of func. The representation must conform to the rules below.
- Throw a
TypeError exception.
toString Representation Requirements:
-
The string representation must have the syntax of a
FunctionDeclaration ,FunctionExpression ,GeneratorDeclaration ,GeneratorExpression ,AsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration ,AsyncGeneratorExpression ,ClassDeclaration ,ClassExpression ,ArrowFunction ,AsyncArrowFunction , orMethodDefinition depending upon the actual characteristics of the object. - The use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.
-
If the object was defined using ECMAScript code and the returned string representation is not in the form of a
MethodDefinition orGeneratorMethod then the representation must be such that if the string is evaluated, usingevalin a lexical context that is equivalent to the lexical context used to create the original object, it will result in a new functionally equivalent object. In that case the returned source code must not mention freely any variables that were not mentioned freely by the original function's source code, even if these “extra” names were originally in scope. -
If the implementation cannot produce a source code string that meets these criteria then it must return a string for which
evalwill throw aSyntaxError exception.
19.2.3.6 Function.prototype [ @@hasInstance ] ( V )
When the @@hasInstance method of an object F is called with value V, the following steps are taken:
- Let F be the
this value. - Return ?
OrdinaryHasInstance (F, V).
The value of the name property of this function is "[Symbol.hasInstance]".
This property has the attributes { [[Writable]]:
This is the default implementation of @@hasInstance that most functions inherit. @@hasInstance is called by the instanceof operator to determine whether a value is an instance of a specific
v instanceof F
evaluates as
F[@@hasInstance](v)
A instanceof by exposing a different @@hasInstance method on the function.
This property is non-writable and non-configurable to prevent tampering that could be used to globally expose the target function of a
19.2.4 Function Instances
Every Function instance is an ECMAScript Function.prototype.bind method (
Function instances have the following properties:
19.2.4.1 length
The value of the length property is an integer that indicates the typical number of arguments expected by the function. However, the language permits the function to be invoked with some other number of arguments. The behaviour of a function when invoked on a number of arguments other than the number specified by its length property depends on the function. This property has the attributes { [[Writable]]:
19.2.4.2 name
The value of the name property is a String that is descriptive of the function. The name has no semantic significance but is typically a variable or
Anonymous functions objects that do not have a contextual name associated with them by this specification do not have a name own property but inherit the name property of
19.2.4.3 prototype
Function instances that can be used as a prototype property. Whenever such a Function instance is created another ordinary object is also created and is the initial value of the function's prototype property. Unless otherwise specified, the value of the prototype property is used to initialize the [[Prototype]] internal slot of the object created when that function is invoked as a
This property has the attributes { [[Writable]]:
Function objects created using Function.prototype.bind, or by evaluating a prototype property.
19.3 Boolean Objects
19.3.1 The Boolean Constructor
The Boolean
- is the intrinsic object
%Boolean% . - is the initial value of the
Booleanproperty of theglobal object . - creates and initializes a new Boolean object when called as a
constructor . - performs a
type conversion when called as a function rather than as aconstructor . - is designed to be subclassable. It may be used as the value of an
extendsclause of a class definition. Subclass constructors that intend to inherit the specifiedBooleanbehaviour must include asupercall to theBooleanconstructor to create and initialize the subclass instance with a [[BooleanData]] internal slot.
19.3.1.1 Boolean ( value )
When Boolean is called with argument value, the following steps are taken:
- Let b be
ToBoolean (value). - If NewTarget is
undefined , return b. - Let O be ?
OrdinaryCreateFromConstructor (NewTarget,"%BooleanPrototype%", « [[BooleanData]] »). Set O.[[BooleanData]] to b.- Return O.
19.3.2 Properties of the Boolean Constructor
The Boolean
- has a [[Prototype]] internal slot whose value is the intrinsic object
%FunctionPrototype% . - has the following properties:
19.3.2.1 Boolean.prototype
The initial value of Boolean.prototype is the intrinsic object
This property has the attributes { [[Writable]]:
19.3.3 Properties of the Boolean Prototype Object
The Boolean prototype object:
- is the intrinsic object
%BooleanPrototype% . - is an ordinary object.
- is itself a Boolean object; it has a [[BooleanData]] internal slot with the value
false . - has a [[Prototype]] internal slot whose value is the intrinsic object
%ObjectPrototype% .
The abstract operation thisBooleanValue(value) performs the following steps:
19.3.3.1 Boolean.prototype.constructor
The initial value of Boolean.prototype.constructor is the intrinsic object
19.3.3.2 Boolean.prototype.toString ( )
The following steps are taken:
- Let b be ?
thisBooleanValue (this value). - If b is
true , return"true"; else return"false".
19.3.3.3 Boolean.prototype.valueOf ( )
The following steps are taken:
- Return ?
thisBooleanValue (this value).
19.3.4 Properties of Boolean Instances
Boolean instances are ordinary objects that inherit properties from the Boolean prototype object. Boolean instances have a [[BooleanData]] internal slot. The [[BooleanData]] internal slot is the Boolean value represented by this Boolean object.
19.4 Symbol Objects
19.4.1 The Symbol Constructor
The Symbol
- is the intrinsic object
%Symbol% . - is the initial value of the
Symbolproperty of theglobal object . - returns a new Symbol value when called as a function.
- is not intended to be used with the
newoperator. - is not intended to be subclassed.
- may be used as the value of an
extendsclause of a class definition but asupercall to it will cause an exception.
19.4.1.1 Symbol ( [ description ] )
When Symbol is called with optional argument description, the following steps are taken:
- If NewTarget is not
undefined , throw aTypeError exception. - If description is
undefined , let descString beundefined . - Else, let descString be ?
ToString (description). - Return a new unique Symbol value whose [[Description]] value is descString.
19.4.2 Properties of the Symbol Constructor
The Symbol
- has a [[Prototype]] internal slot whose value is the intrinsic object
%FunctionPrototype% . - has the following properties:
19.4.2.1 Symbol.asyncIterator
The initial value of Symbol.asyncIterator is the well known symbol @@asyncIterator (
This property has the attributes { [[Writable]]:
19.4.2.2 Symbol.for ( key )
When Symbol.for is called with argument key it performs the following steps:
- Let stringKey be ?
ToString (key). - For each element e of the GlobalSymbolRegistry
List , do- If
SameValue (e.[[Key]], stringKey) istrue , return e.[[Symbol]].
- If
Assert : GlobalSymbolRegistry does not currently contain an entry for stringKey.- Let newSymbol be a new unique Symbol value whose [[Description]] value is stringKey.
- Append the
Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the GlobalSymbolRegistryList . - Return newSymbol.
The GlobalSymbolRegistry is a
| Field Name | Value | Usage |
|---|---|---|
| [[Key]] | A String | A string key used to globally identify a Symbol. |
| [[Symbol]] | A Symbol |
A symbol that can be retrieved from any |
19.4.2.3 Symbol.hasInstance
The initial value of Symbol.hasInstance is the well-known symbol @@hasInstance (
This property has the attributes { [[Writable]]:
19.4.2.4 Symbol.isConcatSpreadable
The initial value of Symbol.isConcatSpreadable is the well-known symbol @@isConcatSpreadable (
This property has the attributes { [[Writable]]:
19.4.2.5 Symbol.iterator
The initial value of Symbol.iterator is the well-known symbol @@iterator (
This property has the attributes { [[Writable]]:
19.4.2.6 Symbol.keyFor ( sym )
When Symbol.keyFor is called with argument sym it performs the following steps:
19.4.2.7 Symbol.match
The initial value of Symbol.match is the well-known symbol @@match (
This property has the attributes { [[Writable]]:
19.4.2.8 Symbol.prototype
The initial value of Symbol.prototype is the intrinsic object
This property has the attributes { [[Writable]]:
19.4.2.9 Symbol.replace
The initial value of Symbol.replace is the well-known symbol @@replace (
This property has the attributes { [[Writable]]:
19.4.2.10 Symbol.search
The initial value of Symbol.search is the well-known symbol @@search (
This property has the attributes { [[Writable]]:
19.4.2.11 Symbol.species
The initial value of Symbol.species is the well-known symbol @@species (
This property has the attributes { [[Writable]]:
19.4.2.12 Symbol.split
The initial value of Symbol.split is the well-known symbol @@split (
This property has the attributes { [[Writable]]:
19.4.2.13 Symbol.toPrimitive
The initial value of Symbol.toPrimitive is the well-known symbol @@toPrimitive (
This property has the attributes { [[Writable]]:
19.4.2.14 Symbol.toStringTag
The initial value of Symbol.toStringTag is the well-known symbol @@toStringTag (
This property has the attributes { [[Writable]]:
19.4.2.15 Symbol.unscopables
The initial value of Symbol.unscopables is the well-known symbol @@unscopables (
This property has the attributes { [[Writable]]:
19.4.3 Properties of the Symbol Prototype Object
The Symbol prototype object:
- is the intrinsic object
%SymbolPrototype% . - is an ordinary object.
- is not a Symbol instance and does not have a [[SymbolData]] internal slot.
- has a [[Prototype]] internal slot whose value is the intrinsic object
%ObjectPrototype% .
The abstract operation thisSymbolValue(value) performs the following steps:
19.4.3.1 Symbol.prototype.constructor
The initial value of Symbol.prototype.constructor is the intrinsic object
19.4.3.2 Symbol.prototype.toString ( )
The following steps are taken:
- Let sym be ?
thisSymbolValue (this value). - Return
SymbolDescriptiveString (sym).
19.4.3.2.1 Runtime Semantics: SymbolDescriptiveString ( sym )
When the abstract operation SymbolDescriptiveString is called with argument sym, the following steps are taken:
Assert :Type (sym) is Symbol.- Let desc be sym's [[Description]] value.
- If desc is
undefined , let desc be the empty string. Assert :Type (desc) is String.- Return the
string-concatenation of"Symbol(", desc, and")".
19.4.3.3 Symbol.prototype.valueOf ( )
The following steps are taken:
- Return ?
thisSymbolValue (this value).
19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
This function is called by ECMAScript language operators to convert a Symbol object to a primitive value. The allowed values for hint are "default", "number", and "string".
When the @@toPrimitive method is called with argument hint, the following steps are taken:
- Return ?
thisSymbolValue (this value).
The value of the name property of this function is "[Symbol.toPrimitive]".
This property has the attributes { [[Writable]]:
19.4.3.5 Symbol.prototype [ @@toStringTag ]
The initial value of the @@toStringTag property is the String value "Symbol".
This property has the attributes { [[Writable]]:
19.4.4 Properties of Symbol Instances
Symbol instances are ordinary objects that inherit properties from the Symbol prototype object. Symbol instances have a [[SymbolData]] internal slot. The [[SymbolData]] internal slot is the Symbol value represented by this Symbol object.
19.5 Error Objects
Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base objects for user-defined exception classes.
19.5.1 The Error Constructor
The Error
- is the intrinsic object
%Error% . - is the initial value of the
Errorproperty of theglobal object . - creates and initializes a new Error object when called as a function rather than as a
constructor . Thus the function callError(…)is equivalent to the object creation expressionnew Error(…)with the same arguments. - is designed to be subclassable. It may be used as the value of an
extendsclause of a class definition. Subclass constructors that intend to inherit the specifiedErrorbehaviour must include asupercall to theErrorconstructor to create and initialize subclass instances with an [[ErrorData]] internal slot.
19.5.1.1 Error ( message )
When the Error function is called with argument message, the following steps are taken:
- If NewTarget is
undefined , let newTarget be theactive function object , else let newTarget be NewTarget. - Let O be ?
OrdinaryCreateFromConstructor (newTarget,"%ErrorPrototype%", « [[ErrorData]] »). - If message is not
undefined , then- Let msg be ?
ToString (message). - Let msgDesc be the PropertyDescriptor { [[Value]]: msg, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Perform !
DefinePropertyOrThrow (O,"message", msgDesc).
- Let msg be ?
- Return O.
19.5.2 Properties of the Error Constructor
The Error
- has a [[Prototype]] internal slot whose value is the intrinsic object
%FunctionPrototype% . - has the following properties:
19.5.2.1 Error.prototype
The initial value of Error.prototype is the intrinsic object
This property has the attributes { [[Writable]]:
19.5.3 Properties of the Error Prototype Object
The Error prototype object:
- is the intrinsic object
%ErrorPrototype% . - is an ordinary object.
- is not an Error instance and does not have an [[ErrorData]] internal slot.
- has a [[Prototype]] internal slot whose value is the intrinsic object
%ObjectPrototype% .
19.5.3.1 Error.prototype.constructor
The initial value of Error.prototype.constructor is the intrinsic object
19.5.3.2 Error.prototype.message
The initial value of Error.prototype.message is the empty String.
19.5.3.3 Error.prototype.name
The initial value of Error.prototype.name is "Error".
19.5.3.4 Error.prototype.toString ( )
The following steps are taken:
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - Let name be ?
Get (O,"name"). - If name is
undefined , let name be"Error"; otherwise let name be ?ToString (name). - Let msg be ?
Get (O,"message"). - If msg is
undefined , let msg be the empty String; otherwise let msg be ?ToString (msg). - If name is the empty String, return msg.
- If msg is the empty String, return name.
- Return the
string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg.
19.5.4 Properties of Error Instances
Error instances are ordinary objects that inherit properties from the Error prototype object and have an [[ErrorData]] internal slot whose value is Object.prototype.toString.
19.5.5 Native Error Types Used in This Standard
A new instance of one of the NativeError objects below is thrown when a runtime error is detected. All of these objects share the same structure, as described in
19.5.5.1 EvalError
This exception is not currently used within this specification. This object remains for compatibility with previous editions of this specification.
19.5.5.2 RangeError
Indicates a value that is not in the set or range of allowable values.
19.5.5.3 ReferenceError
Indicate that an invalid reference value has been detected.
19.5.5.4 SyntaxError
Indicates that a parsing error has occurred.
19.5.5.5 TypeError
TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause.
19.5.5.6 URIError
Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.
19.5.6 NativeError Object Structure
When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in name property of the prototype object, and in the implementation-defined message property of the prototype object.
For each error object, references to NativeError in the definition should be replaced with the appropriate error object name from
19.5.6.1 The NativeError Constructors
Each NativeError
- creates and initializes a new NativeError object when called as a function rather than as a
constructor . A call of the object as a function is equivalent to calling it as aconstructor with the same arguments. Thus the function callNativeError(…)is equivalent to the object creation expressionnew NativeError(…)with the same arguments. - is designed to be subclassable. It may be used as the value of an
extendsclause of a class definition. Subclass constructors that intend to inherit the specified NativeError behaviour must include asupercall to the NativeErrorconstructor to create and initialize subclass instances with an [[ErrorData]] internal slot.
19.5.6.1.1 NativeError ( message )
When a NativeError function is called with argument message, the following steps are taken:
- If NewTarget is
undefined , let newTarget be theactive function object , else let newTarget be NewTarget. - Let O be ?
OrdinaryCreateFromConstructor (newTarget,"%NativeErrorPrototype%", « [[ErrorData]] »). - If message is not
undefined , then- Let msg be ?
ToString (message). - Let msgDesc be the PropertyDescriptor { [[Value]]: msg, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Perform !
DefinePropertyOrThrow (O,"message", msgDesc).
- Let msg be ?
- Return O.
The actual value of the string passed in step 2 is either "%EvalErrorPrototype%", "%RangeErrorPrototype%", "%ReferenceErrorPrototype%", "%SyntaxErrorPrototype%", "%TypeErrorPrototype%", or "%URIErrorPrototype%" corresponding to which NativeError
19.5.6.2 Properties of the NativeError Constructors
Each NativeError
- has a [[Prototype]] internal slot whose value is the intrinsic object
%Error% . - has a
nameproperty whose value is the String value `"NativeError"`. - has the following properties:
19.5.6.2.1 NativeError.prototype
The initial value of NativeError.prototype is a NativeError prototype object (
This property has the attributes { [[Writable]]:
19.5.6.3 Properties of the NativeError Prototype Objects
Each NativeError prototype object:
- is an ordinary object.
- is not an Error instance and does not have an [[ErrorData]] internal slot.
- has a [[Prototype]] internal slot whose value is the intrinsic object
%ErrorPrototype% .
19.5.6.3.1 NativeError.prototype.constructor
The initial value of the constructor property of the prototype for a given NativeError
19.5.6.3.2 NativeError.prototype.message
The initial value of the message property of the prototype for a given NativeError
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given NativeError
19.5.6.4 Properties of NativeError Instances
NativeError instances are ordinary objects that inherit properties from their NativeError prototype object and have an [[ErrorData]] internal slot whose value is Object.prototype.toString (