JavaScript. What is object object, ordinary object, exotic object.
No name for data object.
JavaScript is annoying, you have this “data object” e.g. {cat:3, dog:4}, there is no offcial proper name for it.
ecma spec sometimes refers to it as “object object” due to this very complicated hack:
console.assert( Reflect.apply(Object.prototype.toString, {}, []) === "[object Object]", );
yet, in ecma spec, it distinguish “ordinary object” vs “exotic object”.
ordinary object basically means objects that use the default internal methods ([[Get]], [[Set]], [[DefineOwnProperty]], and so on).
Anything that overrides those methods is an exotic object.
however, function, date, regex, are all ordinary objects.
lol.
basically, there is is no standard official way to distinguish the common data object {cat:3, dog:4} vs object that has special behavior.
what is object object
ecmascript spec used to call normal objects as 'object object'. To distinguish it from function object or regular expression object or date object or other special objects. is that true
(ai answer)
Yes, with a small wording caveat.
Older ECMAScript editions (especially ES3 and ES5) did treat “plain” objects as a distinct kind of object from Function, Date, RegExp, Array, etc. The mechanism was the internal [[Class]] property:
new Object()/{}got[[Class]]"Object"- functions got
"Function" - dates got
"Date" - regexes got
"RegExp" - and so on
Object.prototype.toString then produced the familiar tags: "[object Object]", "[object Function]", "[object Date]", "[object RegExp]", etc. That is where the informal phrase “Object object” comes from. The spec itself also titled sections “Object Objects”, “Function Objects”, “Date Objects”, and so on.
So the distinction you describe was real. The exact words were usually [[Class]] "Object" or “Object objects”, not the doubled phrase “object object” as a formal term.
ES2015 replaced [[Class]] with ordinary vs exotic objects plus Symbol.toStringTag. The old toString tags are still produced for compatibility.
what is ordinary objects, exotic objects
in js, what is ordinary object, what is exotic object
(ai answer)
In JavaScript (ECMAScript), every object implements a set of essential internal methods that control how properties, prototypes, extensibility, etc. work:
[[GetPrototypeOf]], [[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[GetOwnProperty]], [[DefineOwnProperty]], [[HasProperty]], [[Get]], [[Set]], [[Delete]], [[OwnPropertyKeys]]
(Functions also have [[Call]] / [[Construct]].)
Ordinary object
An object that uses the default implementations of those methods (specified in the spec as “Ordinary Object Internal Methods”).
Typical examples:
{ a: 1 }Object.create(proto)new Object()- Most objects created by user-defined constructors / classes
- User-defined functions (they are ordinary objects that also have
[[Call]])
They behave like a plain map of properties plus a prototype chain.
Exotic object
Any object that overrides one or more of those internal methods, so its property / prototype / length / indexing behavior is not the default.
The spec says: any object that is not an ordinary object is an exotic object.
Common built-in exotic objects:
| Kind | What’s special |
|---|---|
| Array | length and integer indexes are coupled; setting length can delete elements |
String object (new String("hi")) |
Indexed properties reflect the string’s characters |
| Arguments | Maps indexed properties to the corresponding formal parameters |
Bound function (fn.bind(...)) |
Custom [[Call]] / [[Construct]] that forwards to the original |
| TypedArray / Integer-indexed | Indexes map onto a backing ArrayBuffer with typed storage |
| Proxy | All internal methods go through traps |
| Module namespace | Exports are live bindings; some properties are non-writable / non-configurable in special ways |
| Immutable prototype | Object.prototype (and a few others) refuse to change [[Prototype]] |
Host objects (DOM nodes, etc.) can also be exotic.
Quick mental model
- Ordinary = “normal object semantics.”
- Exotic = “this object cheats on at least one internal method so it can do something the default object model doesn’t allow.”
You almost never need to think about this day-to-day, but it explains why Array length works the way it does, why Proxies can intercept everything, and why Object.prototype can’t have its prototype changed.
list all ordinary object in js
list all ordinary object in js
(ai answer)
You cannot list “all ordinary objects” as a closed set of types. Ordinary object is a behavior category: the object uses the default internal methods. Almost every object you create is ordinary. Only a few built-in kinds are exotic.
What counts as ordinary
Anything created like this is an ordinary object:
{}new Object()Object.create(proto)(includingObject.create(null))- most
class/ constructor instances Object.fromEntries(...)- objects made by
OrdinaryObjectCreatein the spec
Also ordinary (they have extra internal slots, but default property semantics):
- user functions (
function,() => {}, methods, generators, async functions) - most built-in functions (
parseInt,Math.max,Array.prototype.map, constructors likeDate,Map,Promise, …) DateinstancesRegExpinstancesMap,Set,WeakMap,WeakSetPromiseErrorand the other error typesBoolean/Number/BigInt/Symbolwrapper objectsArrayBuffer,SharedArrayBuffer,DataViewWeakRef,FinalizationRegistryJSON,Math,Reflect,Atomics(the namespace objects)- most prototype objects (
Date.prototype,Map.prototype,Array.prototype, …) - most iterator objects (
[1,2][Symbol.iterator](), map/set iterators, etc.) - generator / async-generator instances
- unmapped
argumentsobjects (strict-mode functions)
Functions are ordinary objects that also have [[Call]] (and sometimes [[Construct]]).
What is not ordinary (exotic)
These override at least one essential internal method:
| Kind | Why exotic |
|---|---|
Array instances |
special length / index handling |
Typed arrays (Uint8Array, …) |
integer-indexed exotic objects |
String wrapper objects (new String("hi")) |
virtual index properties |
Proxy |
all internal methods forwarded to traps |
bound functions (fn.bind(...)) |
custom [[Call]] / [[Construct]] |
mapped arguments objects |
indices alias parameters |
Object.prototype |
immutable-prototype exotic |
| module namespace objects | special exports / [[SetPrototypeOf]] |
| some host objects | window, DOM lists, etc. |
Object.prototype is the common surprise: it is an immutable prototype exotic object, not an ordinary object.
Quick mental model
({}) // ordinary new Date() // ordinary /abc/ // ordinary function f() {} // ordinary (and callable) [] // exotic new Proxy({}, {}) // exotic new Uint8Array(4) // exotic new String("x") // exotic Object.prototype // exotic
So: there is no finite list of “the ordinary objects in JS.” There is a small list of exotic kinds; everything else with default property behavior is ordinary.