What is an ECMAScript native object?

In accordance with ECMA-262 own facility

in an ECMAScript implementation whose semantics are fully defined by this specification and not by the host environment

An embedded object is defined as

provided by the ECMAScript implementation, regardless of the host environment that is present at the beginning of ECMAScript execution.

with a note

Standard inline objects are defined in this specification, and others can define and define the ECMAScript implementation. Each inline object is a native object.

If the native object is fully defined by the ECMA-262 specification and not the host environment, and the ECMAScript implementation can define and define new built-in objects, how can this new built-in object be native objects when they are not fully defined by the ECMA-262 specification?

What am I missing?

+4
source share
3 answers

They are "native" because they come with an ECMAScript implementation. The host environment is usually an application that consists of an implementation of ECMAScript and several other interfaces that work together. For instance,

  • A web browser is a host environment consisting of an implementation of ECMAScript, a DOM interface, a rendering engine, a user interface, etc.
  • Windows Script Host - a host environment consisting of an ECMAScript implementation, a VBScript implementation, etc.
  • Node.js - a host environment consisting of an implementation of ECMAScript (V8), HTTP interfaces, etc.

Inline objects are required to inherit from Object or Function , whereas host objects — objects provided by the host environment but not necessarily present at the start of execution — are not required, but they can (and sometimes do).

Examples of native objects defined by ECMA-262

  • Object() , Array() , Date()
  • Math , JSON , a Global object.

Examples of built-in embedded objects not defined by ECMA-262

Examples of host objects

  • DOM objects, document and window
  • console
+6
source

The semantics of the native object are fully defined by ECMA-262. The object itself cannot be.

So, we have three levels of objects:

  • Standard embedded objects : defined by ECMA-262 and follow the semantics of ECMA-262. Example: Object .
  • Other built-in objects : not defined in ECMA-262, but following the semantics of ECMA-262. Example: setTimeout .
  • Host Objects : Does not follow ECMA-262 semantics; they can have strange behavior of any kind and interact with EMCA-262 built-in objects in strange and unexpected ways (for example, about various internal properties). Example: NodeList .
+2
source

native object definition - relative member of host object
As a window.console object, a host object that Ecma262 has not been documented to tell the browser how to implement it.
And Ecma262 is just a project to indicate the language. The implementation of ECMAScript is actually a browser business. This means that the implementation complies with the specification for the object type , we can say that it is built-in object , although they do not work exactly the same.

0
source

Source: https://habr.com/ru/post/1380214/


All Articles