Search notes:
Javascript: objects
Object-properties
An object is a collection of zero or more (named?) properties .
These properties store one of
a primitive value (which is a member of one of the built-in primitive types )
another object
a function (which is called a method if associated with an object via property)
A property is identified by its
key value which is
a string (referred to as property name ), or
a Symbol (which is a built in type )
Each property can be assigned attributes that further control how the property can be used. For example, it's possible to set the Writable attribute of a property to false
so that it cannot be assigned a different value.
A property is one of
data property
accessor property
A
constructor is a
Function
object that is stored in an object's property named
prototype
.
Prototype
Each object has a special (built-in) property which is referred to as the object's prototype .
This prototype is either another object or null
.
The name of this property is not standardised (most
browsers , however, settled on the name
__proto__
).
In order to access an object's prototype, Object.getPrototypeOf(obj)
.
Because the prototype is also an object, there is a so called prototype chain which goes on until an object's prototype is null
.
When the
Javascript engine tries to evaluate
obj.prop
, it first tries to resolve the property named
prop
in the object
obj
. If it doesn't find it there, it tries to find this property in the prototype chain.
Ordinary vs exotic objects
Internal slots and methods
TODO:
Are internal slots and methods the same thing?
…
Internal slots (of all (ordinary?) objects?):
[[Extensible]]
A Boolean-valued slot that all ordinary objects have, which is most of the time(?) initially set to true
. As soon as set to false
, it is no longer possible to add properties to the object or to modify the [[Prototype]]
internal slot.
[[Prototype]]
A slot that all ordinary objects have. Its value is either null
or an object. In a Module Namespace Exotic Object , this value is always null
. In a global object , its value is implementation defined.
[[ConstructorKind]]
[[ECMAScriptCode]]
[[Environment]]
[[FormalParameters]]
[[HomeObject]]
The object whose [[GetPrototypeOf]]
provides the object where super
property lookup begins
[[IsClassConstructor]]
If true
, calling [[Call]]
will throw a TypeError
exception
[[Realm]]
Every built-in function object has a [[Realm]]
internal slot whose value is the Realm Record of the realm for which the object was initially created.
[[ScriptOrModule]]
which refers to either the script or module where the function was created.
[[Strict]]
signifies a strict function if true
[[SourceText]]
A sequence of Unicode code points representing the source code for the function
[[ThisMode]]
How this
references are interpreted. (Can be lexical , strict or global )
Internal methods of a Function object include
[[Call]]
TODO: The Proxy exotic object below. The global object does not have a [[Call]]
internal method.
Bound function exotic objects do not have the internal slots of ordinary function objects. Instead, they come with
[[BoundTargetFunction]]
the wrapped function object.
[[BoundThis]]
[[BoundArguments]]
String exotic objects (or just String objects) have the internal slots of ordinary objects plus the following internal slots (methods?):
[[DefineOwnProperty]]
[[GetOwnProperty]]
[[OwnPropertyKeys]]
An Integer-Indexed exotic object has the same internal slots as an ordinary object plus
[[ViewedArrayBuffer]]
[[ArrayLength]]
[[ByteOffset]]
[[ContentType]]
[[TypedArrayName]]
Argument objects have the same internal slots as ordinary objects plus
[[ParameterMap]]
(???) For ordinary argument objects, [[ParameterMap]]
whose value is always undefined
An ArgGetter and ArgSetter function is an (anonymous) built-in function with the following two internal slots
A Module Namespace Exotic Object have these internal slots:
[[Module]]
[[Exports]]
[[Prototype]]
Always null
For-in iterator instances
[[Object]]
[[ObjectWasVisited]]
[[VisitedKeys]]
[[RemainingKeys]]
RegExp String iterator instances:
[[IteratingRegExp]]
[[IteratedString]]
[[Global]]
[[Unicode]]
[[Done]]
Array Iterator instances
[[IteratedArrayLike]]
[[ArrayLikeNextIndex]]
[[ArrayLikeIterationKind]]
Proxy exotic objects
Internal method Handler method
[[GetPrototypeOf]]
getPrototypeOf
[[SetPrototypeOf]]
setPrototypeOf
[[IsExtensible]]
isExtensible
[[PreventExtensions]]
preventExtensions
[[GetOwnProperty]]
getOwnPropertyDescriptor
[[DefineOwnProperty]]
defineProperty
[[HasProperty]]
has
[[Get]]
get
[[Set]]
set
[[Delete]]
deleteProperty
[[OwnPropertyKeys]]
ownKeys
[[Call]]
apply
[[Construct]]
construct
What about these?
What about these internal slots :
[[ArrayLength]]
[[BooleanData]]
[[Class]]
[[ErrorData]]
[[DateValue]]
[[IteratedString]]
[[NumberData]]
[[OriginalFlags]]
Used in RegExp objects, might contain the flags s
, i
, m
, u
.
[[OriginalSource]]
Used in RegExp objects
[[ProxyHandler]]
[[ProxyTarget]]
[[RegExpMatcher]]
[[StringData]]
[[StringNextIndex]]
[[SymbolData]]
The Symbol value represented by a Symbol object
What about these internal methods :
[[Construct]]
which the global object does not have. TODO: Proxy exotic objects above.
[[DefineOwnProperty]]
For example found in the String exotic object
[[Delete]]
[[IsExtensible]]
[[Get]]
[[GetOwnProperty]]
For example found in the String exotic object
[[HasProperty]]
[[OwnPropertyKeys]]
For example found in the String exotic object
[[PreventExtensions]]
[[Set]]
[[SetPrototypeOf]]
Built-in objects
Many built-in objects are functions and can be called with arguments.
Some of the built-in objects are also constructors (which are intended to be used with the new
operator).
Unless specified otherwise, a built-in object that is callable as a function is a built-in function object with the characteristics described in 9.3
Unless specified otherwise, the [[Extensible]]
internal slot of a built-in object initially has the value true
.
Every built-in function object has a [[Realm]]
internal slot whose value is the Realm Record of the realm for which the object was initially created.
Compare with the typed arrays Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array.
Value properties
globalThis
Infinity
NaN
undefined
Function properties
eval()
isFinite()
isNaN()
parseFloat()
parseInt()
decodeURI()
decodeURIComponent()
encodeURI()
encodeURIComponent()
escape()
Deprecated
unescape()
Deprecated
Error objects
Error
AggregateError
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
InternalError Non-standard
Indexed collections
Array
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
BigInt64Array
BigUint64Array
Float16Array
Float32Array
Float64Array
Structured data
ArrayBuffer
SharedArrayBuffer
DataView
Atomics
JSON
Managing memory
WeakRef
FinalizationRegistry
Control abstraction objects
Iterator
See also the Generator
object.
AsyncIterator
Promise
GeneratorFunction
AsyncGeneratorFunction
Generator
A subclass of the hidden Iterator
object, returned by generator functions (functions with a *
)
AsyncGenerator
AsyncFunction
Internationalization
Intl
Intl.Collator
Intl.DateTimeFormat
Intl.DisplayNames
Intl.DurationFormat
Intl.ListFormat
Intl.Locale
Intl.NumberFormat
Intl.PluralRules
Intl.RelativeTimeFormat
Intl.Segmenter
TODO
What about
arguments
The global Object .
WebAssembly (WebAssembly.Module, WebAssembly.Instance, WebAssembly.Memory, WebAssembly.Table, WebAssembly.CompileError, WebAssembly.LinkError, WebAssembly.RuntimeError)
Intrinsic objects
Some intrinsic objects include
%ArrayIteratorPrototype%
%Boolean%
The intrinsic object for the Boolean constructor
%BigInt64Array%
%eval%
The intrinsic object for the eval()
function.
%Error.prototype%
%Float32Array%
%Float64Array%
%ForInIteratorPrototype%
%Function.prototype%
?
%Int8Array%
%Int16Array%
%Int32Array%
%IteratorPrototype%
%Number%
%Object.prototype%
%ObjectPrototype%
%ObjProto_toString%
%MapPrototype%
%RegExpStringIteratorPrototype%
%TypedArray%
%Uint8Array%
%Uint8ClampedArray%
%BigUint64Array%
%Uint16Array%
%Uint32Array%
%String%
%Symbol%
The initial value of Symbol.prototype.constructor
%SymbolPrototype%