ECMAScript 2019 Introduction

This standard defines the ECMAScript 2019 language and is the ninth edition of the ECMAScript language specification. Since its first release in 1997, ECMAScript has become one of the most widely used programming languages ​​in the world. He is best known as a language embedded in web browsers, but is also widely used in servers and embedded applications.

ECMAScript is based on several originating technologies, the most famous being Netscape’s JavaScript and Microsoft’s JScript. The language was invented by Netscape’s Brendan Eich and first appeared in the company’s Navigator 2.0 browser. It has appeared in all subsequent Netscape browsers and in all browsers that Microsoft has started since Internet Explorer 3.0.

ECMAScript Language Development

The development of the ECMAScript language specification began in November 1996. The first edition of the Ecma standard was adopted by the Ecma Joint Conference in June 1997.

The First Edition of ECMAScript

This (first edition) Ecma standard was submitted to ISO/IEC JIC 1 for fast channel adoption and was approved as an international standard ISO/IEC 16262 in April 1998. The second edition of ECMA-262 was adopted at the 1998 Ecma Joint Conference to ensure full compliance with ISO/IEC 16262. The changes in the first and second editions are at the editorial level.

The third edition of the standard introduces powerful regular expressions, better string handling, new control statements, try/catch exception handling, stricter error definitions, formatting of digital output, and minor changes in expected future language development. The third edition of the ECMAScript standard was adopted by the Ecma Joint Conference in December 1999 and as ISO/IEC 16262:2002 in June 2002.

ECMAScript and World Wide Web

After the third edition was released, ECMAScript was heavily used on the World Wide Web, and it became the programming language supported by all Web browsers. In order to develop the fourth edition of ECMAScript, a lot of meaningful work was done. However, this work was not completed and was not released as the fourth edition of ECMAScript, but some of them were included in the sixth edition of development (work).

The fifth edition of ECMAScript (262-5 to the ECMA TH release) for those languages have been widely implemented in browser specifications compiled substantial explanation, and adds support for new features since the third edition of the publication appears.

ECMAScript Features

These features include Accessor properties, Reverse and create the object under examination , control attributes characteristic of the object , More array manipulation functions, support for JSON object encoding format , and an enhanced error checking and program security in strict mode . The fifth edition was adopted at the December 2009 Ecma Joint Conference.

The fifth edition was submitted to ISO/IEC JIC 1 for rapid channel adoption and was approved as the international standard ISO/IEC 16262:2011. The 5.1 version of the ECMAScript standard contains fewer corrections and is consistent with ISO/IEC 16262:2011. It was adopted in June 2011 at the Ecma Joint Conference.

The sixth edition began as a key development in 2009, when the fifth edition was being prepared for publication.

However, the previous focus of the experiment and the language enhancement design work can be traced back to the third edition of 1999. In fact, the completion of the sixth edition is the result of fifteen years of hard work. This release adds support for large applications, library creation , and compilation goals with ECMAScript as the other language. The main enhancements include modularity , class declarations , lexical block scopes , iterators and generators , asynchronous programming promises , destructuring patterns , and correct tail calls .

ECMAScript Built-in Library Extension Support

The ECMAScript built-in library extension supports additional data abstractions, including Map , Set , and arrays of binary values , as well as Unicode supplemental characters for use in strings and regular expressions . The built-in library is also extended by subclasses. The sixth edition provides the basis for regular , progressive languages and library enhancements . The sixth edition was adopted by the Ecma Joint Conference in June 2015.

ECMAScript 2016 uses the new annual release strategy of the Ecma TC39 committee and the first ECMAScript version of the open development process. Build a plain text source document from the ECMAScript 2015 source document as a base to support further development on GitHub.

In the year of this standard development, hundreds pull requests and issues were submitted, representing thousands of bug fixes, editor fixes and other improvements. In addition, many software tools were developed to help with this work, including Ecmarkup, Ecmarkdown and Grammarkdown. ES2016 also includes support for a new exponentiation operator and include a new method called Array.prototype.

ECMAScript 2017

The ECMAScript 2017 specification introduces Async functions , shared memory , and smaller language and library enhancements for atomic , bug fixes , and editor updates. The Async function promise-returning improves the asynchronous programming experience by providing function syntax.

Shared memory and atoms introduce a new memory model that allows multiple agents to communicate using atomic operations to ensure that programs have a well-defined execution order even on parallel CPUs. This specification also includes new static methods for Object: Object.values, Object.entries and Object.getOwnPropertyDescriptors.

This specification, version 9 supports asynchronous iteration by introducing asynchronous iterator protocols and asynchronous generators. The specification also includes four new regular expression features: the dotAll flag, named capture groups, Unicode attribute escaping, and backsight assertions. It also includes REST parameters and extended operators to support object properties. There are also many small updates, edits and specifications that contribute to our community.

Ecma TC39

Many individuals and organizations have made a significant contribution to the current and previous versions of the Ecma TC39. In addition, there is a vibrant community that supports TC39’s efforts for ECMAScript. The community reviewed many drafts, submitted a large number of bug reports, performed implementation experiments, and provided test suites, which could benefit from ECMAScript developers around the world.

Regrettably, however, everyone and organizations that contribute to this cannot be acknowledged.

Wirfs-Brock allen

the ECMA-262, 6 TH version Project Editor

Terlson Brian

the ECMA-262, 7 TH version Project Editor

ECMAScript Standards

This standard defines the ECMAScript 2018 general programming language.

ECMAScript Consistency

An implementation that conforms to the ECMAScript standard should meet the following recommendations:

All types, values, objects, properties, functions, and program syntax and semantics described in this specification must be provided and supported.

The input to interpret the source text must be consistent with the latest versions of the Unicode standard and the ISO/IEC 10646 standard.

The program provided by the application interface needs to adapt to the language and cultural habits of countries using different natural languages, and ECMA-402 the implementation of the latest version must be compatible with the interface of this specification.

Additional types, values, objects, properties, and methods that are beyond the specification should be provided. Especially for those objects that are mentioned in the documentation but do not describe their properties, those properties and the values ​​corresponding to the properties should be provided.

Some programs or regular expression syntax that are not mentioned in the specification should be supported.

ECMAScript Reference Standard

In order to implement an application that conforms to this specification, the following referenced documents are indispensable. For documents marked with a date, only the version of the label is applied. For documents that are not dated, the latest version of the document (including any revisions).

ISO/IEC 10646:2003: Information Technology – Generic Multiple Octet Coded Character Set (UCS) and Amendment 1:2005, Amendment 2:2006, Amendment 3:2008, and Amendment 4:2008 , and other amendments, corrections, successor standards

ECMA-402, ECMAScript 2015 Internationalization API Specification . https://www.ecma-international.org/publications/standards/Ecma-402.htm

ECMA-404, JSON Data Exchange Formatting . https://www.ecma-international.org/publications/standards/Ecma-404.htm

ECMAScript Overview

This section contains a non-normative overview of the ECMAScript language.

ECMAScript is an object-oriented programming language that performs computations and manipulates computational objects in a hosted environment.

The ECMAScript defined here is not intended to be self-sufficient in calculation; in fact, the specification does not specify the input of external data or the output of the calculation result. Instead, we expect that the computing environment of the ECMAScript program will not only provide the objects and capabilities described in this specification, but also specific environment objects.

In addition to the description that these objects should provide certain properties that can be accessed by ECMAScript programs, some methods are called. In addition, other descriptions and actions regarding it are outside the scope of this Code.

ECMAScript – Scripting Language to General Purpose Language

ECMAScript was originally designed as a scripting language, but is now widely used as a general-purpose programming language. A scripting language is a programming language used to manipulate, customize, and automate existing system capabilities. In such systems, useful functionality is already available through the user interface, and scripting languages ​​are mechanisms that expose these functions to program control.

In this way, the existing system is called a host environment that provides objects and capabilities, thus completing the functions of the scripting language. The scripting language is for professional and non-professional programmers.

Originally designed as a web scripting language , ECMAScript provides a mechanism for making web pages more vibrant and capable of server-side computing based on the Web B/S architecture. ECMAScript is now used to provide core scripting capabilities across multiple hosts. This document therefore describes the language core in addition to the specific hosting environment.

ECMAScript usage has gone far beyond simple scripting and is now used for a full range of programming tasks in many different environments and sizes. As the scope of use of ECMAScript has expanded, its capabilities and capabilities have also expanded. ECMAScript is now a full-featured general-purpose programming language.

EMCAScript Vs Other Programming Languages

Some of ECMAScript’s capabilities are similar to those in other programming languages, especially C, Java, Self, and the following:

  • ISO/IEC 9899:1996, Programming Languages ​​– C .
  • Gosling, James, Bill Joy and Guy Steele. The Java TM Language Specification . Addison Wesley Publishing Co., 1996.
  • Ungar, David, and Smith, Randall B. Self: The Power of Simplicity. OOPSLA ’87 Conference Proceedings , pp. 227-241, Orlando, FL, October 1987.
  • IEEE Standard for the Scheme Programming Language . IEEE Std 1178-1990.

ECMA Web Script

The web browser provides an ECMAScript hosting environment for client-side computing, including instance objects such as delegate windows, menus, pop-ups, dialogs, text fields, anchors, frames, history, cookies, and input/output.

In addition, the host environment provides the ability for script code to handle events such as focus changes, page and image loading, unloading, errors and interruptions, selections, form submissions, and mouse interactions. Combine user interface elements with script code in HTML, pin and calculate text, and images to display pages. The script code does not require a main program to respond to user interaction.

The WEB server provides a different mechanism than the client, such as requests, clients, files, etc., as well as data locking and sharing. Provides a customized user interface for web-based applications that can be used for distributed computing between the client and server through the use of browser-side scripts and server-side scripts.

Both WEB browsers and servers that support ECMAScript complement their own hosting environment as ECMAScript to complete the ECMAScript execution environment.

ECMAScript Overview

The following is an informal overview of ECMAScript – just a part of the language. This overview is not part of the standard.

ECMAScript is object-based: the underlying language and the main capabilities are provided through objects, and an ECMAScript program is a set of communicable objects. In ECMAScript, an object is a collection of zero or more properties.

Each attribute has to be used to determine how their properties , such as when a characteristic property to Writable False Any ECMAScript code that attempts to assign a different value to this property will fail.

ECMAScript Built-in Data Types

Attributes are containers of other objects, primitive values , and functions . The original value is one of the following built-in type members: Undefined , Null , Boolean , Number , String , and Symbol; An object is one of the built-in type Object members, and a function is a callable object. The function called by the object through the property is called the method.

ECMAScript Built-in Objects

ECMAScript defines a set of built-in objects to outline the definition of ECMAScript entities.

These built-in objects include global objects ; basic language Runtime semantics Objects, including Object, Function, Boolean, Symbol, various Error objects; and values representative of operation of the object, including Math, Number, Date; text processing object String, ; RegExp index value set Array objects, and the specific digital data having a value of nine kinds of representation Typed Array objects; generic objects  Map , Set; support for structured data JSON, ArrayBuffer, SharedArrayBuffer, DataView and other objects; support for controlling abstract generator functions, Promise objects; and reflection objects Proxy, Reflect.

ECMAScript also defines a set of built-in operators.

The ECMAScript operators include various unary operations, multiplication operators, addition operators, displacement operators, relational operators, equality operators, binary operators, binary logical operators, assignment operators, and comma operators.

Large ECMAScript programs are supported through modules that allow programs to be split into multiple statements and definition sequences. Each module explicitly identifies the declarations provided by other modules it uses, and which declarations are available to other modules.

The ECMAScript syntax is intentionally similar to the Java syntax. The ECMAScript syntax is loose, making it an easy-to-use scripting language. For example, a variable does not need to declare its concrete type, nor does it need to associate a property type with a declaration, nor does it require a textual declaration before calling the defined function.

ECMAScript Objects

Although ECMAScript includes syntax for defining classes, ECMAScript objects are not class-based like C++, Smalltalk, and Java. Instead, objects can be created in a variety of ways, including literal symbols, or through Constructor Create an object and then run the code to initialize all or part of its property values, assigning initial values ​​to those properties.

Each Constructor Has named a “prototype”property of a function, this property is used to implement prototype-based inheritance and shared properties .

Constructor Create an object with a new expression: for example, new Date(2009, 11)create a new Date object. Call one without using new Constructor Result by Constructor It is decided by itself. For example, Date()generate a string that represents the current date and time, not an object.

Each by Constructor The created object has an implicit reference (called the prototype of the object ) linked to Constructor The “prototype”property value. Furthermore, a prototype may have a non-empty implicit reference linked to its prototype, and so on, which is called a prototype chain .

When a reference is made to an attribute of an object, the reference points to the attribute of the first object in the prototype chain that contains the name of the attribute. In other words, first check the property of the same name of the directly mentioned object.

If the object contains an attribute with the same name, the reference points to this attribute. If the object does not contain the attribute with the same name, the next step is to check the prototype of the object; and so on.

Figure 1: Object/Prototype Relationships

In general, an instance of a class-based object-oriented language has a state, a class owns a method, and can only inherit structures and behaviors. In ECMAScript, objects have states and methods, and structures, behaviors, and states are all inherited.

All objects that do not directly contain specific properties share this property and property values ​​contained in their prototype. Figure 1 illustrates this:

CF is a Constructor(Also an object). Five objects have been used new to create an expression: cf 1 , cf 2 , cf 3 , cf 4 ,cf 5 . Each object has the name q1and q2 attributes.

The dotted line indicates the implicit prototype relationship; for example: The prototype of cf 3 is CF p .Constructor CF it has named P1and P2two properties, which CF P , CF2 . 1 , CF2 2 , CF2 . 3 , CF2 . 4 , CF2 . 5 is not visible. CF2 P named CFP1 attribute shared CF2 . 1 , CF2 2 , CF2 . 3 , CF2 . 4 , and CF2 . 5 (no CF2 ), and the CF2 P can not find implicit in any named prototype chain q1, q2or CFP1 attributes . Please note that CF and CF p There are no implicit prototype links between them.

Unlike class-based object languages, properties can be dynamically added to objects by way of assignment.

That is,Constructor It is not necessary to name or assign all or any of the attributes of the constructed object. In the above figure, you can add a new attribute attribute to CF p by adding a new shared attribute to cf 1 , cf 2 , cf 3 , cf 4 , and cf 5 .

Although ECMAScript objects are not class-based in nature, it is convenient to implement a class-like abstraction based on constructors, prototype objects, and method generic patterns. The ECMAScript built-in object itself follows this class pattern. Starting with ECMAScript 2015, the ECMAScript language includes class definition syntax that allows programmers to define objects as concisely as built-in objects.

ECMAScript Strict Variations

The ECMAScript language recognizes that some developers may wish to limit the use of new features in the language. They may do this for security reasons, avoid features that they think are error-prone, gain an enhanced error check, or other reasons. Therefore, strict variants of the language are defined in ECMAScript.

Strict variations of the language, excluding certain specific syntax and semantic features of the ECMAScript language, and modifying the detailed semantics of certain functions. Strict variants also specify additional error conditions that must be thrown for error exception reporting, even if they are not errors in a non-strict language form.

The strict variant of ECMAScript is often referred to as the strict mode of language . Strict mode selection and use are explicitly applied to the unique ECMAScript code unit level, ECMAScript strict mode syntax and semantics. Since the strict mode of the grammar code unit level is selected, the strict mode imposes a local effect limitation only in this code unit. Strict mode does not limit or modify ECMAScript semantics at any level and must operate consistently across multiple code units. An ECMAScript program can contain both rigorous and non-strict mode code units. In this case, the strict mode only applies to code that is actually executed within the strict mode code unit.

To comply with this specification, ECMAScript implementations must implement both the unrestricted ECMAScript language and the strict schema variants of ECMAScript defined by this specification. In addition, the implementation must also support the use of unrestricted and strict mode code units in the same program.

ECMAScript Terms and Definitions

The following terms and definitions are used in this document.

1) Type – In this specification, A collection of data values ​​defined in.

2) Original value – Means One of the Undefined, Null, Boolean, Number, Symbol, String types defined in

NOTE: A raw value directly represents the lowest level of data implemented by the language

3) Object – Members of type Object

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

4) Constructor – Create and initialize objects Function object

NOTE: Constructor The prototype property value is used to implement inheritance and shared a prototype object.

5) Prototype – An object that provides shared properties for other objects

NOTE: When Constructor Create an object that is implicitly referenced in order to resolve an object’s property reference Constructor Of prototype property. By program expressions_constructor_.prototype can refer to Constructor The prototype property, added to the object in the prototype property is shared by inheritance, all objects are shared prototype. In addition, you can use Object.create built-in functions to create a new object by explicitly specifying the prototype.

6) Ordinary object – The default behavior has objects that have internal methods that all objects must support.

7) Exception object – The default behavior is missing one or more objects of the necessary internal methods

NOTE: Any object is not Ordinary object It is an exception object.

8) Standard object – Object whose semantics are defined by this specification

9) Built-in object – ECMAScript implementation specifies and provides objects

NOTE: Standard built-in objects are defined by this specification, and ECMAScript implementations can specify and define other built-in ones. Constructor Is a built-in object, also a Constructor.

10) Undefined value – An original value that is used when the variable is not assigned a value

11) Undefined type – Value only Undefined Type of value

12) null value – Indicates the original value of any object value deliberately defaulted

13) Null type – Value only Null Type of value

14) Boolean value – Member of type Boolean

NOTE: There are only two values, True with False.

15) Boolean type – Original value True with False Type of composition

16) Boolean object – Standard built-in constructor Boolean Instance of one of the Object type members

NOTE: By using newan expression to a Boolean value as a parameter to call Boolean Constructor To create a Boolean object. The resulting object contains an internal property whose value is this Boolean value. A Boolean object can be cast to a Boolean value.

17) String value – Finite ordered sequence original value consisting of zero or more 16-bit unsigned integers

NOTE: A String value is a member of type String. Usually each integer value in the sequence represents a single 16-bit unit of UTF-16 text. However, for its value, ECMAScript only requires a 16-bit unsigned integer, and there are no restrictions or requirements.

18) String type – A collection of all possible String values

19) String object – Standard built-in Constructor String Instance, one of the Object type members

NOTE: By using newan expression to a String parameter called value String Constructor To create a String object. The resulting object contains an internal property with a value of this String. Will String Constructor Called as a function to cast a String object to a String value.

20) Number value – Original value of 64-bit double-precision binary in IEEE 754-2008 format

NOTE: A numeric value is a member of a numeric type that directly represents a number.

21) Number type – A collection of all possible Number values, including special “Not-a-Number” (NaN) values, positive infinity ,negative infinity

22) Number object – Standard built-in Constructor Number An instance of one of the Object type members

NOTE: By using newan expression to a parameter called digital value Number Constructor To create a Number object. The resulting object contains an internal property with a value of this Number. Will Number Constructor Called as a function to cast a Number object to a numeric value.

23) Endless – Positive infinity

24) NaN – Value of IEEE 754-2008 “Not-a-Number”

25) Symbol value – Represents the original value of a unique, non-string attribute key object

26) Symbol type – All possible sets of Symbol values

27) Symbol object – Standard built-in Constructor Symbol An instance of one of the Object type members

28) Function – One of the Object type members that can be called as a subroutine

NOTE: In addition to its properties, functions contain executable code and state to determine the behavior when called. The code for the function is not limited to ECMAScript.

29) built-in functions – Built-in object as a function

NOTE: For example, parseInt and Math.exp are built-in functions. An implementation can provide implementation-dependent built-in functions not described in this specification.

30) properties – Part of an object that associates a key (a String value or a Symbol value) with a value

NOTE: Attributes may appear as direct data values ​​(original values, objects, or one) depending on the value of the attribute Function object) or an indirect pair of accessor functions.

31) Method – Function as a property value

NOTE: When a function is called as a method of an object, this object will act as This The value is passed to the function.

32) Built-in method – As a method of built-in functions

NOTE: The standard built-in methods are defined by this specification, and the ECMAScript implementation can be specified to provide additional additional built-in methods.

33) Characteristic – Define internal values ​​for some properties of an attribute

34) Own attribute – Attributes directly owned by the object

35) Inherited properties – Not the object’s own property, but the property of the object’s prototype (the prototype’s own or inherited properties)

ECMAScript Symbol Convention Grammar and lexical – Context-free grammar

A context-free grammar consists of multiple productions . On the left side of each production there is anl value of an abstract symbol called a nonterminal , and on the right there is one or more right values ​​of a sequence of nonterminals and terminators . Any grammar whose terminator comes from the specified set of letters.

A production chain is a production that contains only one nonterminal and zero or more terminators as its rvalue.

A single distinguishable nonterminal term in a sentence—the target character , given a language context-free grammar. In other words, iteratively replaces any set of terminal sequences (possibly infinite) consisting of any left-valued non-terminals in the sequence with a production right-value.

Lexical and regular grammar

Word French law has a match 10.1 Defined Source Character The terminator of the rule is a Unicode code point . It defines a set of productions, fromTarget symbol InputElementDiv, InputElementTemplateTail,or InputElementRegExp, InputElementRegExpOrTemplateTail Start, describes how to translate such a sequence of characters into a sequence of input elements.

Input elements other than blanks and comments form the terminator of the ECMAScript syntax grammar, which are called ECMAScript tokens . These tokens are reserved words, identifiers, literals, punctuation marks in the ECMAScript language.

In addition, the line terminator, although not considered a tokens, will be part of the input element stream and will be used to guide the process to automatically insert a semicolon. Discarding of single blank and single-line comments will not occur in the stream of input elements of the grammar grammar.

If one MultiLineComment (Ie, in the form of /**/comments, whether or not span multiple lines) does not contain a line terminator will be directly discarded, but if a MultiLineComment Contains one or more terminators, then the comment is replaced with a line terminator that becomes part of the stream of grammar grammar input elements.

The regular grammar of ECMAScript is given . The terminator character of this grammar is also SourceCharacter definition. It defines a set of productions, from Target symbol Pattern Initially, it describes how to translate such a sequence of characters into a regular expression pattern.

The two colons “::” are used as separators to separate grammatical and regular grammar productions. Lexical and regular grammars share certain productions.

Numeric string grammar

A grammar used to convert a string to a numeric value. This grammar is similar to a part of the digital literal grammar method and has a terminator SourceCharacter.

The three colons “:::” are used as separators to separate the production of numeric string grammars.

Grammatical grammar

The ECMAScript tokens defined by the word French method are the terminators of this grammar. It defines a series of productions, from two optional Target symbol number Script as well as Module Initially, it describes the sequence of tokens that form the normal independent components of the ECMAScript program.

When a code point stream is parsed into an ECMAScript Script or ModuleIt is first converted into a stream of input elements by the lexical program; then the stream of input elements is parsed using a single grammar grammar. There is a syntax error – the token in the input element stream cannot be parsed into a single target nonterminal (Script or Module) – The input stream will not leave any tokens.

When a parse is successful, it constructs a parse tree. One root tree structure is that each node is a Parse Node . Each Parse Node is an instance of a symbol in the grammar . It represents a span of source code text derived from such symbols.

The root node of the parse tree represents the entire source code text and is parsed Target symbol An example of this. When a Parse Node is an instance of a non-terminal, it is also an instance of a production whose lvalue is a non-terminal. In addition, it has zero or more children , producing each symbol in the right-value: each child’s Parse Node is an instance of the corresponding symbol.

The new Parse Nodes are re-instantiated each time the parser is called, which means that parsing the same source text will never be reused. Considered to be the same Parse Node if and only if they represent the same source text range, are instances of the same syntax symbol, and are resolved nodes that are invoked by the same parser

NOTE 1: Parsing the same string multiple times will result in different Parse Nodes, for example:

eval(str); eval(str);

NOTE 2: Parse Nodes are artificial definitions of the specification and do not need to be implemented using similar data structures.

Use only the colon ” : ” as a separator to separate the production of grammatical lexical grammars.

But for which token sequences are correct by ECMAScript Script or Module The explanation accepted is not complete. Some additional token sequences can also be accepted. In other words, those sequences will be described by grammar as long as the semicolon is added to some part of the sequence (such as before the line terminator). In addition, some token sequences described by grammar are not accepted if a row terminator appears in some “awkward” places.

In some cases, to avoid ambiguity, the grammar grammar uses a generalized production that allows the token sequence to form an illegal ECMAScript. Script or Module.

For example, this technique is used in object literals and object deconstruction modes. In this case, a more restrictive supplemental grammar is provided that further limits the acceptable token sequence.

In general, if ” P is not covering an N “, an early error rule would define an error condition, where P is a Parse Node (an instance of a normal production) and N is a non-terminal character that complements the grammar. Here, the token sequence that originally matched P is again used as N.

Target symbol Number analysis. (If N uses syntax parameters, set them to the same value that was used when P initially parsed). If the token sequence cannot be resolved to a single instance of N , an error will be generated and no token will be left. The algorithm then accesses the parsing result of the phrase “the N that is covered by P “. This will always be a parsing node ( an instance of N that is unique to a given P ), so any parsing failure will be detected by an early error rule.

Grammar Notation

Whether in the production of grammar or in this specification, the grammar, regular grammar, and the terminology of the numeric string grammar are displayed in monospaced fonts. These will appear as scripts. All terminal code points specified in this way are interpreted as appropriate basic Latin Unicode code points, rather than from any other code point similar to the Unicode range.

Nonterminals are shown in italics .

The definition of a nonterminal (also called a production) is given by a non-terminal name and one or more colons defined afterwards. (The number of colons represents the grammar to which the production belongs.) One or more alternative right-values ​​of the non-terminal are immediately following the next line. For example, the grammar definition:

WhileStatement: While(Expression)Statement

Indicates this nonterminal WhileStatement Represents while token, followed by left parenthesis token, followed by Expression, followed by the closing parenthesis token, followed by Statement. Appeared here Expression with Statement It is itself a non-terminal.

Another example, the grammar definition:

ArgumentList: AssignmentExpression ArgumentList,AssignmentExpression

Indicate this ArgumentList Can represent one AssignmentExpression,or ArgumentList, followed by a comma followed by a AssignmentExpression.

This one ArgumentList The definition is recursive, that is, it defines itself. The result is that one ArgumentList May contain any positive arguments separated by commas, each argument expression is a AssignmentExpression. Thus, nonterminals share the definition of recursion.

A suffix subscript ” opt ” may appear for a terminator or non-terminal , indicating that it is an optional symbol. The inclusion of optional symbols actually specifies the inclusion of two right-valued values, one for omitting optional elements and the other for optional elements. this means:

VariableDeclaration:BindingIdentifier InitializerOpt

Is a simple abbreviation for the following:

VariableDeclaration:BindingIdentifier BindingIdentifier Initializer

as well as:

IterationStatement: For(LexicalDeclaration ExpressionOpt;ExpressionOpt)Statement

Is a simple abbreviation for the following:

IterationStatement:For(LexicalDeclaration;ExpressionOpt)StatementFor(LexicalDeclaration Expression;ExpressionOpt)Statement

Also an abbreviation of the following:

IterationStatement: For(LexicalDeclaration😉Statement For(LexicalDeclaration;Expression)Statement For(LexicalDeclaration Expression😉StatementFor(LexicalDeclaration Expression;Expression)Statement

So in this example, the nonterminal IterationStatement There are actually four right-values ​​to choose from.

The production can be parameterized by a subscript such as ” [parameters] “, which appears as a suffix in the non-terminal of the production definition. ” parameters ” can be either a separate name or a comma-separated list of names. The parameterized production is a series of abbreviations that produce a combination of all the combinations of parameter names beginning with an underscore and appended to the parameterized non-terminal. This means:

StatementList[Return]:ReturnStatementExpressionStatement

Is the following abbreviation:

StatementList: ReturnStatement Expression Statement StatementList_Return:ReturnStatement Expression Statement

as well as:

StatementList[Return, In]:ReturnStatement Expression Statement

Is the following abbreviation:

StatementList: ReturnStatement ExpressionStatement StatementList_Return:ReturnStatement ExpressionStatement StatementList_In: ReturnStatement ExpressionStatement StatementList_Return_In:ReturnStatement ExpressionStatement

Multiple parameters produce a combination of several productions, and it is not necessary to reference all in one complete syntax.

References to production-type non-terminal right-values ​​can also be parameterized, for example:

StatementList: ReturnStatement ExpressionStatement[+In]

Is the following abbreviation:

StatementList: ReturnStatementExpressionStatement_In

Another example:

StatementList: ReturnStatement ExpressionStatement[~In]

Is the following abbreviation:

StatementList: ReturnStatement ExpressionStatement

A non-terminal reference may have both a parameter list and an ” opt ” suffix. E.g:

VariableDeclaration: BindingIdentifier Initializer[+In]Opt

Is the following abbreviation:

VariableDeclaration: BindingIdentifierBindingIdentifierInitializer_In

In the right non-terminal reference parameter name is preceded by ” ? “, so that the parameter value depends on whether the parameter name of the left symbol reference of the current production appears. E.g:

VariableDeclaration[In]:BindingIdentifierInitializer[?In]

Is the following abbreviation:

VariableDeclaration: BindingIdentifier InitializerVariableDeclaration_In: BindingIdentifierInitializer_In

If the r value selection is prefixed with “[+parameter]”, it means that the selection is only available when the named parameter is used to reference the non-terminal character of the production. If the r value selection is prefixed with “[~parameter]”, it means that the selection is only available if the named parameter is not a non-terminal character used to reference the production. this means:

StatementList[Return]:[+Return]ReturnStatement ExpressionStatement

Is the following abbreviation:

StatementList: ExpressionStatement StatementList_Return: ReturnStatement ExpressionStatement

Another example:

StatementList[Return]:[~Return]ReturnStatement ExpressionStatement

Is the following abbreviation:

StatementList: ReturnStatement ExpressionStatement StatementList_Return: ExpressionStatement

When the word ” one of ” follows one or more semicolons in the grammar definition , the subsequent one or more lines of the terminator are an optional definition. For example, ECMAScript’s lexical method contains the following productions:

NonZeroDigit::One of 123456789

It is just the following abbreviation:

NonZeroDigit::123456789

If “[empty]” appears in a production rvalue, it implies that the right value of this production does not contain a terminator or a nonterminal.

If “[lookahead ∉ set ]” appears in a production rvalue, it implies that if the immediately entered token sequence is a member of the given set ( set ), then this production may not be used.

This collection can be represented by a comma-separated list of one or two element termination sequences wrapped in curly braces. For convenience, this collection can also be represented by a non-terminal character, in which case it represents a collection of all the terminators that can be expanded by non-terminal symbols. If the collection contains a single terminator, the phrase “[lookahead ≠ terminal ]” may be used.

For example, give a definition:

DecimalDigit::One of 0123456789 DecimalDigits:: DecimalDigit DecimalDigits DecimalDigit

Then define:

LookaheadExample::n[lookahead ∉ { 1, 3, 5, 7, 9 }]DecimalDigits DecimalDigit[lookahead ∉ DecimalDigit]

Matches the letter n followed by one or more decimal digits starting with an even number, or a decimal number followed by a non-decimal number.

Similarly, if “[lookahead ∈ set ]” appears for the right-value of the production, it means that the production-only token sequence that is entered immediately after is a member of the given set ( set ) can be used. If the collection contains only a single terminator, you can use “[lookahead == terminal ]”.

If the right side of the production appears “[no LineTerminator Here]”, then it means that this production is a restricted production: if LineTerminator Appears at the specified location of the input stream, then this production will not be applied.

For example, production:

ThrowStatement: Throw[no LineTerminator Here]Expression;

If one LineTerminator The throw token that appears in the script and Expression At the time, it implies that this production may not be used.

Unless prohibited by a restricted production LineTerminator Appear, otherwise any number LineTerminator The occurrence of this may occur between any two consecutive tokens in the input element stream and does not affect the semantic acceptability of the script.

When a multi-code point token appears in an optional part of a word French or numeric string grammar, it means that the code point sequence will form a token.

A production right value may specify some extensions that are not allowed by ” but not “, and then imply that the extension will be excluded. For example, production:

Identifier::IdentifierName But not ReservedWord

Means non-terminal Identifier May be replaced by an arbitrary sequence of code points that can be replaced by the provided IdentifierName, but the code points of the same sequence cannot be replaced. ReservedWord.

Finally, some nonterminals are described by descriptive phrases written in sans-serif fonts. In such cases, it is impractical to list all the optional parts.

SourceCharacter::Any Unicode code point

Algorithm convention

This specification typically uses a numbered list to specify the steps of the algorithm. These algorithms are used to precisely specify the semantics required for the ECMAScript language structure. This algorithm is not intended to imply any technique used by any particular implementation. In practice, perhaps a more efficient algorithm can be used to implement a given function.

The algorithm may be explicitly parameterized, in which case the parameter name and usage must be provided as part of the algorithm definition.

Algorithm steps can be subdivided into multiple consecutive sub-steps. The sub-steps need to be represented by indentation and can be further divided into sub-steps of indentation.

The outline numbering convention is used as the identification substep, the first level substeps are marked with lowercase alphabetic characters, and the second level of small steps are marked with lowercase Roman numerals. If the step exceeds three levels, then these rules are marked from the fourth level starting with the number repeat. E.g:

  1. Top-level step
    1. Substep.
    2. Substep.
      • Subsubstep.
        1. Subsubsubstep
          • Subsubsubsubstep
            • Subsubsubsubsubstep

A step or substep may use “if” to assert the condition of its substeps. In such cases, these substeps can only be applied to situations where the “if” assertion is true. If a step or substep starts with “else”, then this indicates a negative assertion of the same level of the previous “if” assertion.

A step might specify an iterator of its substeps.

A step beginning with ” Assert :” asserts a condition that is constant in its algorithm. Such assertions are used to explicitly display algorithm invariants, otherwise it will be implicit. Such assertions do not add additional semantic requirements, so implementations do not have to be checked. They are used just to make the algorithm clearer.

For any value such as “Let x be someValue “, the algorithm step may declare a named alias. These aliases are all of a similar type, ie x and someValue point to the same underlying data, and their modifications are visible to each other. Algorithm steps similar to those cited want to avoid such a need to explicitly copy the value of the right: the “Let_x_ BE A Copy of someValue ” created a someValue shallow copy.

Once the declaration is complete, the alias can be referenced in any subsequent steps and not in the steps preceding the alias declaration. The alias may be modified by a form such as “Set x to someOtherValue “.

ECMAScript Abstract operations

To facilitate their use in multiple places in this specification, some algorithms, which we call abstract operations , are named and written in the form of parameterized functions so that they can be referenced by names in other algorithms. Abstract operations are usually referenced using the function’s application style, such as OperationName( arg1 , arg2 ).

Some abstract operations are treated as if they were abstract polymorphic feeds in a class specification. Such class-like method abstractions are usually referenced by a method application style, such as someValue .OperationName( arg1 , arg2 ).

ECMAScript Syntax-oriented operations

A grammatically oriented operation is a named operation whose definition contains a series of algorithms, each associated with the production of one or more ECMAScript grammars. A production with multiple optional definitions usually has a separate algorithm for each optional part.

When an algorithm is associated with a grammar production, it may refer to the terminal or non-terminal of the optional part of the production as if they were parameters of the algorithm. When this happens, the non-terminal character points to the definition of the optional part of the actual source code that matches it.

When an algorithm is associated with an optional part of a production, this optional part is usually not preceded by a “[ ]” grammar comment. Such comments should only affect the grammatical recognition of the optional parts and should not affect the semantics of the relevant optional parts.

The syntax-directed operation is called with the same parsing node.

  1. Let status be the result of performing SyntaxDirectedOperation of Some NonTerminal.
  2. Let someParseNode be the parse of some source text.
  3. Perform SyntaxDirectedOperation of someParseNode .
  4. Perform SyntaxDirectedOperation of someParseNode passing “value”as the argument.

Unless explicitly stated otherwise, all associated productions have an implicit definition for each operation that may be applied to the non-terminal of the production lvalue. If present, this implicit definition simply applies the same definition to the same parameters again, and for each of the associated production-only right-valued non-terminals, the processing result is then returned.

For example, suppose some algorithms have the following form of steps: “Return the result of evaluation Block“, and there is a production here:

Block:{StatementList}

But the parsing operation is not associated with this production algorithm. So in such cases, the parsing operation implicitly contains the following forms of association:

Runtime semantics: Analysis

Block:{StatementList}

  1. Return the result of evaluation StatementList.

ECMAScript Runtime Semantics

The algorithm that specifies the semantics that must be called at runtime is called runtime semantics . Runtime semantics Abstract operation Or specify a syntax action to define. Such an algorithm must return a completion record.

Implicit completion value

The algorithm of this specification often implicitly returns a [[Type]] value. Normal of Completion Records. Unless an algorithm statement that returns a value is explicitly specified in the context, it returns a Completion Record Value. E.g:

  1. Return “Infinity”.

The same meaning as the following:

  1. Return NormalCompletion( “Infinity”).

However, if the value expression of a “return” statement is one Completion Record Constructed literals, then Completion Record The result will be returned. If this value expression is a pair Abstract operation Call, then the “return” statement simply returns this Abstract operation produced Completion Record.

Abstract operation Completion( compoundRecord ) is used to emphasize the previous calculation Completion Record Was returned. Completion This one Abstract operationReceive a parameter, completionRecord , and then perform the following steps:

  1. Assert: completionRecord is a Completion Record.
  2. Return completionRecord as the Completion Record Of this abstract operation.

A “return” statement with no value in the algorithm step has the same meaning as the following:

  1. Return NormalCompletion( undefined).

Need a complete for any display that is not displayed in a context Completion Record a reference to a value, equivalent to an explicit pair Completion Record a reference to the [[Value]] field, unless Completion Record Is an interrupt completed .

ECMAScript Throwing an exception

Describe the algorithm steps that throw an exception, such as:

  1. Throw a TypeError exception.

The same meaning as the following:

  1. Return ThrowCompletion(a new created TypeError Object).

ECMAScript ReturnIfAbrupt

The algorithm step description or equivalent is:

  1. ReturnIfAbrupt( argument ).

it means:

  1. If argument is an Abrupt completion, return argument .
  2. Else if argument is a Completion Record, let argument be argument .[[Value]].

The algorithm step description or equivalent is:

  1. ReturnIfAbrupt(AbstractOperation()).

The same meaning as the following:

  1. Let hygienicTemp be AbstractOperation().
  2. If hygienicTemp is an Abrupt completion, return hygienicTemp .
  3. Else if hygienicTemp is a Completion Record, let hygienicTemp be hygienicTemp .[[Value]].

The hygienicTemp here is temporary and is only visible in the steps related to ReturnIfAbrupt.

The algorithm step description or equivalent is:

  1. Let result be AbstractOperation(ReturnIfAbrupt( argument )).

The same meaning as the following:

  1. If argument is an Abrupt completion, return argument .
  2. If argument is a Completion Record, let argument be argument .[[Value]].
  3. Let result be AbstractOperation( argument ).

ECMAScript ReturnIfAbrupt Abbreviations

Correct Abstract operation And to ? imply that the calling prefix syntax specified operation ReturnIfAbrupt Need to be applied to the results Completion Record in. For example, the steps:

  1. ? OperationName().

Equivalent to the following steps:

  1. ReturnIfAbrupt(OperationName()).

Similarly, for the style of the program method, the steps are:

  1. ? someValue .OperationName().

Equivalent to:

  1. ReturnIfAbrupt( someValue .OperationName()).

Similarly, the prefix !is used to imply the following abstract syntax specified operation or calls will not return a value to complete interrupted, as a result of Completion Record The [[Value]] field should be used as the return value for the replacement operation. For example, the steps:

  1. Let val be ! OperationName().

Equivalent to the following steps:

  1. Let val be OperationName().
  2. Assert: val is never an Abrupt completion.
  3. If val is a Completion Record, set val to val .[[Value]].

For Runtime semantics Operation by replacing the specified syntax before calling the operation !or ?to use the acronym.

Perform ! SyntaxDirectedOperation of NonTerminal.

ECMAScript Static Semantics

Context-free grammars are not good enough to express all defined rules, whether it is a stream of input elements formed by a legal ECMAScript that will be parsed Script still is Module. In some cases, additional rules are required to be demonstrated using ECMAScript algorithm conventions or essay requirements. Such rules are always associated with a grammar production, called production static semantics.

Static semantic rules have names and are usually defined by an algorithm. A static semantic rule with a name is associated with a grammar production. For each static rule with a name that can be used, a production with multiple optional partial definitions usually defines a unique one for each optional part. algorithm.

Unless otherwise specified in this specification, the optional part of the grammar production implicitly contains a definition of a static semantic rule called symbol that accepts a symbol whose value contains the terminator or non-terminal of the relevant production grammar . The default inclusion definition is:

  1. For each child node child of this Parse Node, do
    • If child is an instance of symbol , return True.
    • If child is an instance of a nonterminal, then
      1. Let contained be the result of child Contains symbol .
      2. If contained is True Return True.
  2. Return False.

The above definition is an explicit rewrite of the production of the specification.

A special static semantic rule is an early (advanced) error rule . Early error rules set early error conditions, they are associated with a specific grammar production. The resolution of most early error rules is not explicitly invoked in the algorithms of this specification.

A conforming implementation must be parsed for the first time Script or Module Before, verify that all are used for parsing Script or Module The early error rules of the production. If any of the early error rules are violated, then Script or Module It is illegal and cannot be parsed.

ECMAScript Mathematical operations

Unless otherwise specified, not including infinity and not including negative 0 (in order to distinguish from positive 0), mathematical operations such as addition, subtraction, negation (logical NOT), multiplication, division, and subsequent mathematical functions defined in the clause should always It is considered to be an accurate result calculated for all real numbers in mathematics.

The floating-point operations in this specification algorithm contain explicit steps that are necessary to handle infinity, signed 0, and rounding. If a mathematical operation or function is applied to a floating point number, then it must be treated as a concrete mathematical value represented by a floating point number; such a floating point number must be finite, and if it is+0 or -0 If so, then the corresponding mathematical value is simply 0.

Mathematical function Abs( x )Used to calculate x absolute value, if x is negative, then the result is – x Otherwise the result is x itself.

Mathematical function Min( x1 , x2 , …, xN ) Calculated from X1 To xN The minimum value. Mathematical function Max( x1 , x2 , …, xN ) Calculated from X1 To xN The maximum value. The fields and scope of these mathematical functions include +∞ with -∞.

symbol”x modulo y( y must be finite and non-zero) to calculate a value k whose sign is consistent with y (or 0), such k is satisfied Abs(k) < Abs(y), and find an integer y such that x – k = q * y .

Mathematical function Floor( x )Produces a largest integer (closest to positive infinity) that is not greater than x .

NOTE

Floor( x ) = x -( x Modulo 1).

ECMAScript data types and values

The algorithm in this specification controls each value with a relevant type. The possible value types are directly defined in this section. These types are further divided into ECMAScript language types and specification types.

In this specification, the “Type( x )” notation is short for “the type of x “, where “type” refers to the ECMAScript language type and specification type defined in this section. When a value is named using the term “empty”, it is equivalent to saying “there is no type of value.”

ECMAScript language type

An ECMAScript language type corresponds to values ​​that are directly used by ECMAScript programmers in the ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Symbol, Number, Object. An ECMAScript language value is a value that has the characteristics of an ECMAScript language type.

  1. Undefined type – The Undefined type has only one value, undefined. Any variable value that has not been assigned a value is undefined.
  2. Null type- The Null type has only one value, null.
  3. Boolean type – It represents a Boolean type trueand falsetwo values of a logical entity.
  4. String type – The String type is a collection of all ordered sequences of zero or more 16-bit unsigned integer values ​​(“elements”) with a maximum length of 2 53 -1 elements. The string type is typically used to represent text data in a running ECMAScript program, in which case each element in the String is treated as a UTF-16 symbol . Each element is considered to occupy a position within the sequence. These locations are indexed with non-negative integers. The first element (if any) is at index 0, the next element (if any) is at index 1, and so on. The length of a String is the number of elements in the sequence (for example, a sixteen-bit value). An empty string has a length of zero and therefore does not contain an element.

The ECMAScript operator does not apply different semantics to interpret string content. The operator interprets each element of the string as a single UTF-16 code unit. However, ECMAScript does not constrain the values ​​of these code units or the relationships between these code units, so further interpreting the contents of a string as a sequence of Unicode code points encoded in UTF-16 must take into account a subformat of the wrong format.

Such special handling operation rules are used for each code unit, so that the numerical ranges 0xD800 0xDBFF (Unicode standard is defined as the first agent , or more formally high symbol agent ) or to a range 0xDC00 0xDFFF (defined as the end of the agent , Or more formal low proxy symbols ):

  • Not First agent Nor is it Tail agent The symbols are interpreted as code points with the same value.
  • Two symbol sequences, the first symbol c1 is a First agent The second symbol c2 is a Tail agent, such two symbols are called Agent pair, is interpreted as a code point with a value of ( c1 – 0xD800) × 0x400 + ( c2 – 0xDC00) + 0x10000 .
  • One First agent or Tail agent But not one Agent pairA portion of the symbols are interpreted as code points having the same value.

Function String.prototype.normalize can explicitly standardize a string value. String.prototype.localeCompare Normalize string values ​​internally, but no other operations implicitly normalize the strings they run. Only words that are explicitly specified as language or locale sensitive will produce language-sensitive results.

NOTE: The rationale behind this design is to keep the implementation of String as simple and efficient as possible. If the ECMAScript source text conforms to Normalized Form C, the string literal guarantee is also standardized as long as they do not contain any Unicode escape sequences.

In this specification, the phrase “the string-concatenation of A , B , …” indicates that the sequence of string code units is the connection of the code units of each parameter.

Symbol type

The Symbol type is a collection of all non-string values ​​that can be used as the value of the Object property’s key.

Each possible Symbol value is unique and immutable.

Each Symbol value will always hold a value associated with it called [[Description]] (it is either Undefined Either a String value).

The well-known Symbol

The well-known Symbols are built-in Symbol values ​​that are explicitly referenced by the algorithms in this specification. They are usually used as keys for attributes whose values ​​are used as extension points for the specification algorithm. Unless otherwise stated, the value of the well-known Symbol is used by all domains shared.

Within this specification, a well-known Symbol value is referenced in the form of @@name, where “name” is a table Table 1 One of the listed values.

Table 1: Well-known Symbol

Canonical name [[Description]] Value and purpose
@@asyncIterator “Symbol.asyncIteratorReturns the object’s default Async Iterator method. By the for- await- of the semantics of the call statement.
@@hasInstance“Symbol.hasInstance”Determine the structure Function object Whether to identify the object as a method of one of the constructor instances. It made instanceof to call operator semantics.
@@isConcatSpreadable“Symbol.isConcatSpreadable”a Boolean value, if true, indicates that an object should be Array.prototype.concat Flattened into the array elements.
@@iterator“Symbol.iterator”Returns the method of an object’s default Iterator. Called by the semantics of the for-of declaration.
@@matchSymbol.match”A regular expression method that matches a string to a regular expression. By String.prototype.match Method call.
@@replace“Symbol.replace”Replace the regular expression method that matches the string substring. By String.prototype.replace Method call.
@@search“Symbol.search”A regular expression method that returns the index of the content in the string that the regular expression matches. By String.prototype.search Method call.
@@species“Symbol.species”A function value property that is used as a constructor to create a derived object.
@@split“Symbol.split”A regular expression method that splits a string at the index position where the regular expression matches. By String.prototype.split Method call.
@@toPrimitive“Symbol.toPrimitive”A method of converting an object to its corresponding original value. By Abstract operation ToPrimitive transfer.
@@toStringTag“Symbol.toStringTag”The String value property used to create the default string description for the object. Built-in method Object.prototype.toString access.
@@unscopables“Symbol.unscopables”
An object value attribute, its own and inherited attribute names are attribute names that are excluded from the with environment binding of the related object.

ECMAScript Number type

The Number type has 18437736874454810627 (ie,2 64 -2 53 +3 Values, indicating that the IEEE 754-2008 value for the double-precision 64-bit format is specified by the IEEE binary floating-point standard, except for 9007199254740990 (ie,2 53 -2 This unique “Not-a-Number” value in the IEEE standard, which is represented as a special in ECMAScript NaNvalue. (noteNaN Value in the program by NaN Expression generation) In some implementations, external code may be able to detect differences between various Not-a-Number values, but this behavior depends on the implementation; for ECMAScript code, all NaN Values ​​are indistinguishable from each other.

NOTE: After a Number value is stored, in an ArrayBuffer or a SharedArrayBuffer are not necessarily the same as the internal representation of the Number value used by the ECMAScript implementation.

There are two other special values ​​called Positive infinity with Negative infinity. For the sake of brevity, these values ​​are respectively represented by symbols. +∞ with -∞ Said. (Note that these two infinite values ​​are represented by procedural expressions +Infinity(or Infinity ) with -Infinityproduce. )

Other 18437736874454810624 (ie,2 64 -2 53 The values ​​are called finite values. Half of them are positive numbers, generally negative numbers; each finite positive number has a corresponding negative number of the same size.

Note that there is one Positive zero, One Negative zero. For the sake of simplicity, they also use+0 with -0 To illustrate. (note these two different 0, through the program expression+0 (or 0) with -0 produce. )

18437736874454810622 (ie 2 64 -2 53 -2 There are two kinds of finite non-zero values:

Of which 18428729675200069632 (ie 2 64 -2 54) values ​​are standard and have the following format

s × m × 2 e

Where s is +1 or -1, m is an integer less than 2 53 but greater than or equal to 2 52 , and e is an integer from -1074 to 971.

The remaining 9007199254740990 (ie 2 53 -2) values ​​are non-standard, with the following format

s × m × 2 e

Where s is +1 or -1, m is a positive integer less than 52, and e is -1074.

Note that all positive and negative integers with a size not greater than 2 53 can be represented in the Number type (in fact, the integer 0 has two representations, +0 with -0).

If a finite value is non-zero and the integer m used to express it (one of the two forms above) is an odd number, then the value has an odd number . Otherwise, it has an even meaning.

In this specification, when x represents an exact non-zero real mathematical quantity (or even an irrational number such as π), “the Number value for x ” means that a Number value is selected in the following manner. Consider the Number type except-0 And two values ​​that are added to the numeric type but are not renderable, 2 1024 (+1 × 2 53 × 2 971) as well as -2 1024(-1 × 2 53 × 2 971) a collection of all finite values. Select a member of this set whose value is closest to x .

If the two values ​​in the set are approximately equal, then choose the one with an even meaning; for this, 2 1024 and-2 1024 These two excess values ​​are considered to have an even meaning. Finally, if you choose 2 1024 , use+∞ Replace it; if you choose -2 1024, use -∞ Replace it; if you choose +0, if and only if x is less than zero, use-0 Replace it; any other selected values ​​do not need to be changed. The result is the Number value of x . (This process is the behavior of the IEEE 754-2008 “round to nearest, ties to even” mode.)

Some ECMAScript operators only handle closed intervals -2 31 To 2 31 -1, or 0 to 2 16 -1The integer. These operators accept values ​​of any Number type and first convert them to the values ​​in the ranges mentioned above.

ECMAScript Object type

An object is logically a collection of attributes. Each attribute is a data attribute or an accessor attribute:

  • The data attribute is associated with a key value and an ECMAScript language value and a set of properties of the Boolean type.
  • The accessor property associates a key value with one or two accessor functions and a set of properties of type Boolean. The accessor function is used to store or retrieve the ECMAScript language value associated with this property.

Attributes are identified by a key value. The key value of an attribute is an ECMAScript String value or a Symbol value. All String values ​​(including empty strings) and Symbol values ​​are valid as the key of the property. The attribute name refers to the key of the attribute and its value is a string.

A value +0or a ≤ 2 53 is an integer of 1 in a string as the attribute value key numeric index is a typical digital String. An array index is in the range +0 ≤ i < 2 32 -1 The integer.

The key of the attribute is used to access the attribute and its value. Attributes have two access methods: get and set , which respectively retrieve and assign values. Properties that are accessible through get and set include both the own property that belongs directly to it , and the inherited property that is provided by other related objects through the inheritance relationship . An inherited property may also be its own property or an inherited property of another object. Each of the object’s own properties must have a different key value than the object’s other own property key values.

All objects are logical collections of attributes, but there are multiple forms of objects in the semantics of the attributes used to access and manipulate them. Ordinary objects are the most common form of objects and have default object semantics. A singular object is an object whose attribute semantics differ from all aspects of the default semantics.

Related JavaScript Tutorials For Beginners

JavaScript Introduction Tutorials
Introduction to JavaScript
Javascript Code editors
Javascript Reference and Specifications
Javascript Developer Console
Javascript Basics
JavaScript Hello World.!
External JavaScript Files
JavaScript Code Structure
JavaScript Variables
Use Strict in JavaScript


Leave a Comment