ECMAScript overview

ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment.

ECMAScript is an object-oriented (scripting) programming language that performs computations and processes computable objects in a specific host environment.

Here are a few important points:

  1. object-oriented
  2. Scripting language
  3. The host environment

Let’s make an explanation according to the above key words.

object-oriented

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.

ECMAScript is object-based: the basic language capabilities and hosting facilities are provided in the form of objects, and the ECMAScript program itself is a collection of interactive objects.

Scripting language

A scripting language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. In such systems, useful functionality is already available through a user interface, and the scripting language is a mechanism for exposing that functionality to program control. In this way, the existing system is said to provide a host environment of objects and facilities, which completes the capabilities of the scripting language.

Scripting languages are programming languages that operate, customize, and automate infrastructure in existing systems. In this system, available functionality is provided to the user in the form of a user interface, and the scripting language itself is a mechanism for exposing interfaces to control programs. In this way, existing systems are called host environments that provide objects and other infrastructure to fulfill the functions of scripting languages.

The host environment

ECMAScript was originally designed as a Web scripting language to manipulate Web pages in a browser and perform server-side computations as part of a Web client-server architecture.

A web browser provides an ECMAScript host environment for client-side computation including, for instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. Further, the host environment provides a means to attach scripting code to events such as change of focus, page and image loading, unloading, error and abort, selection, form submission, and mouse actions. Scripting code appears within the HTML and the displayed page is a combination of user interface elements and fixed and computed text and images. The scripting code is reactive to user interaction and there is no need for a main program.

Web browsers provide a hosting environment for ECMAScript to perform client computations, including: instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, And objects like input/output. In addition, the hosting environment provides a mechanism to bind code to events, such as changes in focus, error terminations for loading and unloading pages and images, selection commits, and mouse actions. Scripting code can appear in HTML, so what we see on a web page is a combination of user interface elements, text images, and so on. Script code can respond to user behavior without the need for the main program.

A web server provides a different host environment for server-side computation including objects representing requests, clients, and files; and mechanisms to lock and share data.

Web servers provide a different hosting environment for server-side computation, which includes the following objects: representing requests, clients, and files; In addition, it provides a mechanism for data locking and data sharing.

object

In ECMAScript, an Object is a collection of zero or more properties, each of which has attributes that describe how it is used. We can think of properties as containers that hold other objects, primitive values, and functions.

ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities.

ECMAScript defines a set of build-in objects that make up ECMAScript entities.

These built-in objects include:

  1. Global Object
  2. ECMAScript runtime base objects Object, Function, Boolean, Symbol, various errors
  3. Math Number Date processing
  4. String text handles String RegExp
  5. Data Set Array TypeArray Map Set
  6. Structured Data Object JSON ArrayBuffer DataView
  7. Abstract control Generator Promise for the object
  8. Object reflects Proxy Reflect

Prototype chain inheritance

Inheritance of ECMAScript objects is not class-based inheritance like Java or C++. Objects can be created using literal notation or constructors. A constructor is a function object, and each constructor has a Prototype property that implements prototype-based inheritance and property sharing. The constructor uses the new operator to do the object creation.

Every object created by a constructor has an implicit reference (called the object’s prototype) to the value of its constructor’s “prototype” property. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain.

Every object A generated by constructorA has an implicit reference to Constructora. prototype ([[Prototype]] in the ECMAScript standard), The corresponding implementation of this reference in Chrome is __proto__), that is, A.__proto__ points to constructora. prototype; In addition, constructora. prototype is itself an object (that is, object B) and may be created by another constructor (constructorB), that is, B.__proto__ points to constructorb. prototype (object O); And so on, until an object’s __proto__ points to the null pointer, forming what we call a prototype chain.

The above process is shown as follows:

Strict mode

background

ECMAScript has been designed to be easy to use and has attracted a large number of developers. The loose language restrictions are good for beginners, but disastrous for advanced ECMAScript programmers.

Strict mode is more restricted to ECMAScript

ECMAScript recognizes this need and makes it possible for developers to limit some of the strangest features at the language level in a strict pattern.

They might do so in the interests of security, to avoid what they consider to be error-prone features, to get enhanced error checking, or for other reasons of their choosing. In support of this possibility, ECMAScript defines a strict variant of the language. The strict variant of the language excludes some specific syntactic and semantic features of the regular ECMAScript language and modifies the detailed semantics of some features. The strict variant also specifies additional error conditions that must be reported by throwing error exceptions in situations that are not specified as errors by the non-strict form of the language.

Some developers are more concerned with security, and in order to achieve this, they often avoid error-prone features, enhance error detection in their code, and so on. To support this requirement, ECMAScript defines a “strict variant” (strict schema) in the language. This strict pattern removes certain syntactic features and corrects some semantic details. In addition, strict mode will throw errors instead of silent failures under certain circumstances compared to non-strict mode.

MDN strict mode has a very detailed instructions: MDN strict mode

Terms and Definitions

Type type

The data type

Primitive Value Indicates the primitive value

Undefined Null Boolean Number Symbol String Specifies the values of the six data types.

A primitive value is a datum that is represented directly at the lowest level of the language implementation.

Raw values are the most basic data, the lowest implementation of the language.

object

A member of type Object

An object is a collection of properties and has a single prototype object. The prototype may be the null value.

  1. An object is a collection of properties
  2. Each object has an internal (implicit) attribute [[prototype]] that points to another object, which we call a prototype object
  3. The prototype object may be null

The constructor constructor

Constructors are function objects that create and initialize objects.

The value of a constructor’s prototype property is a prototype object that is used to implement inheritance and shared properties.

  1. Constructors are functions, and functions are objects
  2. The constructor has an explicit (external) property called Prototype, which is an object, and prototype is the basis for implementing inheritance and property sharing.

The prototype prototype

Stereotypes allow for property sharing between objects.

When a constructor creates an object, Note that object implicitly references the constructor’s prototype property for the purpose of considerations property references. The constructor’s prototype property can be referenced by The program expression constructor. Prototype, And properties added to an object’s prototype are shared through inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified prototype by using the Object.create built-in function.

Ordinary Object Ordinary object

As an ordinary object, it must have some key internal methods that all objects support, and it must support its default behavior.

Exotic objects

Foreign objects may have some key internal methods that behave differently from the default behavior.

standard object

The semantics of standard objects conform to the ECMAScript specification

build-in object

Built-in objects are objects specified and provided by the “ECMAScript implementation “(here understood as host objects or for the JS engine).

Standard built-in objects are defined in this specification. An ECMAScript implementation may specify and supply additional kinds of built-in objects. A built-in constructor is a built-in object that is also a constructor.

Standard built-in objects are defined by the ECMAScript specification. An ECMAScript implementation may provide additional built-in objects. The built-in constructor is a built-in function object.

Conclusion:

  1. An object that conforms to ECMAScript semantics can be called a standard object.
  2. In addition to the built-in objects specified in the ECMAScript specification, ECMAScript implementations also provide built-in objects related to the host environment. For example, the browser environment has location and document objects, which are also called built-in objects.
  3. Standard built-in objects refer specifically to built-in objects defined in the ECMAScript specification.

undefined vaule

Undefined is a primitive type. When a variable is declared and not assigned a value, its value is undefined

Undefined type

There is only one undefined value data type

null value

Null is a primitive type value that represents a null object pointer.

Null type

There is only one NULL worth data type

Boolean value

Boolean data member

There are only two Boolean values, true and false

Boolean type

A data type that contains two original values true false

Boolean object

An instance object of the standard built-in constructor Boolean.

A Boolean object is created by using the Boolean constructor in a new expression, supplying a Boolean value as an argument. The resulting object has an internal slot whose value is the Boolean value. A Boolean object can be coerced to a Boolean value.

String value

A string value is a primitive value, which is a finite ordered sequence of zero or more 16-bit unsigned integers.

A String value is a member of the String type. Each integer value in the sequence usually represents a single 16-bit unit of UTF-16 text. However, ECMAScript does not place any restrictions or requirements on the values except that they must be 16-bit unsigned integers.

String values are constituent members of string data types. Each integer value in the sequence usually represents a 16-bit UTF-16 character set unit. However, ECMAScript does not enforce or require that they be 16-bit unsigned integers.

String type

A string data type is a collection of all string values.

String object

The String object is an instance of the standard built-in constructor String.

Number value

A raw value data that behaves as a double – precision 64-bit value in the IEEE 754-2008 Numerical specification.

A Number value is a member of the Number type and is a direct representation of a number.

Numeric values are all numbers in a numeric data type

Number type

Numeric data types include numeric values NaN (not-a-number) +Infinate -Infinate

Number object

A Number object is an instance of the standard built-in constructor Number.

A Number object is created by using the Number constructor in a new expression, supplying a number value as an argument. The resulting object has an internal slot whose value is the number value. A Number object can be coerced to a number value by calling the Number constructor as a function (20.1.1.1).

NaN

“Not-a-number” in IEEE-754-2008 specification

Infinity

Is infinite

Symbol value

A primitive value used for the unique key of an object that is not a string

Symbol type

The set of all conforming values

Symbol object

An instance of the standard built-in constructor Symbol.

function

An object type member that can be called as a subroutine.

In addition to its properties, A function contains the executable code and state that determines how it missack when invoked. A function’s code may or may not be written in ECMAScript.

In addition to containing properties, a function also contains executable code and states related to the calling behavior. Function code may not be written (empty function).

build-in function

Built-in functions such as parseInt math.exp, etc

property

A property is a part of an object that is an associated String value or Symbol value pair

method

The object property is a function, and the property is called a method

build-in method

Built-in method: This method is a built-in function

attribute

Properties: These are internal values that define the characteristics of the property.

own property

Properties that an object contains itself rather than inheriting from the stereotype chain

inherited property

Inherited properties: Properties obtained from the stereotype chain