What is the difference between a 'standard object' and an 'ordinary object' in ECMAScript?

205 Views Asked by At

Within the Terms and Definitions section of ECMAScript 2021 Language Specification, an ordinary object is defined as:

object that has the default behaviour for the essential internal methods that must be supported by all objects

A standard object is defined as:

object whose semantics are defined by this specification

After reading both definitions, I immediately asked myself, "Isn't the default behavior of the essential internal methods that must be supported by all objects also defined in this specification?"

I've tried searching the specification for both terms, but there are over 100 matches for 'ordinary object' and only a handful of references for 'standard object', which didn't provide additional context that made the distinction between these terms clear to me. I've also tried Google searching and none of the results seem relevant to my question.

What is the difference between an ordinary object and a standard object? What is an example of a scenario in which it is useful to distinguish between between these two types of objects?

2

There are 2 best solutions below

4
On BEST ANSWER
 const user = { firstname: "Jonas" };

That's an ordinary object (as it is not exotic), however it is not a standard object, as the semantics are defined by me and not by the specification. Its behavior, however, is specified (e.g. user.firstname will evaluate to "Jonas").

0
On

Yes, every ordinary object is also a standard object.

The term ordinary object is contrasted with an exotic object, which does have non-default implementations of the internal object methods. Examples of standard exotic objects are proxies, arrays and bound functions.

The term standard object (previously also known as "native object", which led to a lot of confusion) is contrasted with a host object or implementation-defined object, which are specified by a different specification (e.g. HTML5) or implemented in the engine without a formal specification. These can be functions (that are otherwise ordinary) with a host-defined call behaviour (e.g. console.log, setTimeout etc) or totally exotic objects (document.all, nodelists, etc) - see web APIs for an overview of browser-defined objects. Other environments will provide other host-defined objects.

Ordinary objects (with standard, default behavior) whose existence is governed by the host implementation or non-ECMAScript standard may be classified as either, I guess.

Just for reference, the last distinction that is relevant for this terminology discussion is between built-in objects (also builtins) and user-defined objects. The former are created by the implementation at startup, providing the environment that user code can interact with. The latter are constructed by user code at runtime. It does unfortunately become a grey area when exotic objects are constructed by native (non-user) code, these are sometimes called "built-in" as well.

See also What is the difference between native objects and host objects? and In ECMAScript, how are some of native objects also built-in?.