Standard ECMA-262

  • Revision slug: Standard_ECMA-262
  • Revision title: Standard ECMA-262
  • Revision id: 168201
  • Created:
  • Creator: Niquola
  • Is current revision? Нет
  • комментировать /* Обзор */

Revision Content

Обзор

ECMAScript это объектно-ориентированный язык для вычислений и управления объектами в host environment. Те ECMAScript не предназначен для самостоятельного использования и не имеет своей системы ввода-вывода. При этом подразумевается что система, в которую встраивается ECMAScript,обеспечивает не только базовые объекты приведенные в спецификации но и environment-specific host объекы.


is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. ECMAScript as defined here is not intended to be computationally self-sufficient; indeed, there are no provisions in this specification for input of external data or output of computed results. Instead, it is expected that the computational environment of an ECMAScript program will provide not only the objects and other facilities described in this specification but also certain environment-specific host objects, whose description and behaviour are beyond the scope of this specification except to indicate that they may provide certain properties that can be accessed and certain functions that can be called from an ECMAScript program.

   A scripting language is a programming language that is used to manipulate, customise, 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. A scripting language is intended for use by both professional and non-professional programmers. To accommodate non-professional programmers, some aspects of the language may be somewhat less strict.
   ECMAScript was originally designed to be a Web scripting language, providing a mechanism to enliven Web pages in browsers and to perform server computation as part of a Web-based client-server architecture. ECMAScript can provide core scripting capabilities for a variety of host environments, and therefore the core scripting language is specified in this document apart from any particular host environment.
   Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular Java and Self, as described in:
       * Gosling, James, Bill Joy and Guy Steele. The Java™ 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.

Web Scripting

   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.
   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. By using browser-side and server-side scripting together, it is possible to distribute computation between the client and server while providing a customised user interface for a Web-based application.
   Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment.

Language Overview

   The following is an informal overview of ECMAScript --- not all parts of the language are described. This overview is not part of the standard proper.
   ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. An ECMAScript object is an unordered collection of properties each with zero or more attributes that determine how each property can be used --- for example, when the ReadOnly attribute for a property is set to true, any attempt by executed ECMAScript code to change the value of the property has no effect. Properties are containers that hold other objects, primitive values, or methods. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, and String; an object is a member of the remaining built-in type Object; and a method is a function associated with an object via a property.
   ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the Global object, the Object object, the Function object, the Array object, the String object, the Boolean object, the Number object, the Math object, the Date object, the RegExp object and the Error objects Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError.
   ECMAScript also defines a set of built-in operators that may not be, strictly speaking, functions or methods. ECMAScript operators include various unary operations, multiplicative operators, additive operators, bitwise shift operators, relational operators, equality operators, binary bitwise operators, binary logical operators, assignment operators, and the comma operator.
   ECMAScript syntax intentionally resembles Java syntax. ECMAScript syntax is relaxed to enable it to serve as an easy-to-use scripting language. For example, a variable is not required to have its type declared nor are types associated with properties, and defined functions are not required to have their declarations appear textually before calls to them.
Objects
   ECMAScript does not contain proper classes such as those in C++, Smalltalk, or Java, but rather, supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties. All constructors are objects, but not all objects are constructors. Each constructor has a Prototype property that is used to implement prototype-based inheritance and shared properties. Objects are created by using constructors in new expressions; for example, new String("A String") creates a new String object. Invoking a constructor without using new has consequences that depend on the constructor. For example, String("A String") produces a primitive string, not an object.
   ECMAScript supports prototype-based inheritance. Every constructor has an associated prototype, and every object created by that constructor has an implicit reference to the prototype (called the object's prototype) associated with its constructor. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.
   In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, and structure, behaviour, and state are all inherited.
   All objects that do not directly contain a particular property that their prototype contains share that property and its value. The following diagram illustrates this:
   implicit prototype link explicit prototype link 15 -4
   CF is a constructor (and also an object). Five objects have been created by using new expressions: cf1, cf2, cf3, cf4, and cf5. Each of these objects contains properties named q1 and q2. The dashed lines represent the implicit prototype relationship; so, for example, cf3's prototype is CFp. The constructor, CF, has two properties itself, named P1 and P2, which are not visible to CFp, cf1, cf2, cf3, cf4, or cf5. The property named CFP1 in CFp is shared by cf1, cf2, cf3, cf4, and cf5 (but not by CF), as are any properties found in CFp's implicit prototype chain that are not named q1, q2, or CFP1. Notice that there is no implicit prototype link between CF and CFp.
   Unlike class-based object languages, properties can be added to objects dynamically by assigning values to them. That is, constructors are not required to name or assign values to all or any of the constructed object's properties. In the above diagram, one could add a new shared property for cf1, cf2, cf3, cf4, and cf5 by assigning a new value to the property in CFp.

Definitions

   The following are informal definitions of key terms associated with ECMAScript.

Type

   A type is a set of data values.

4.3.2 Primitive Value

   A primitive value is a member of one of the types Undefined, Null, Boolean, Number, or String. A primitive value is a datum that is represented directly at the lowest level of the language implementation.

4.3.3 Object

   An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.

4.3.4 Constructor

   A constructor is a Function object that creates and initialises objects. Each constructor has an associated prototype object that is used to implement inheritance and shared properties.

4.3.5 Prototype

   A prototype is an object used to implement structure, state, and behaviour inheritance in ECMAScript. When a constructor creates an object, that object implicitly references the constructor's associated prototype for the purpose of resolving property references. The constructor's associated prototype 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.

4.3.6 Native Object

   A native object is any object supplied by an ECMAScript implementation independent of the host environment. Standard native objects are defined in this specification. Some native objects are built-in; others may be constructed during the course of execution of an ECMAScript program.

4.3.7 Built-in Object

   A built-in object is any object supplied by an ECMAScript implementation, independent of the host environment, which is present at the start of the execution of an ECMAScript program. Standard built-in objects are defined in this specification, and an ECMAScript implementation may specify and define others. Every built-in object is a native object.

4.3.8 Host Object

   A host object is any object supplied by the host environment to complete the execution environment of ECMAScript. Any object that is not native is a host object.

4.3.9 Undefined Value

   The undefined value is a primitive value used when a variable has not been assigned a value.

4.3.10 Undefined Type

   The type Undefined has exactly one value, called undefined.

4.3.11 Null Value

   The null value is a primitive value that represents the null, empty, or non-existent reference.

4.3.12 Null Type

   The type Null has exactly one value, called null.

4.3.13 Boolean Value

   A boolean value is a member of the type Boolean and is one of two unique values, true and false.

4.3.14 Boolean Type

   The type Boolean represents a logical entity and consists of exactly two unique values. One is called true and the other is called false.

4.3.15 Boolean Object

   A Boolean object is a member of the type Object and is an instance of the built-in Boolean object. That is, a Boolean object is created by using the Boolean constructor in a new expression, supplying a boolean as an argument. The resulting object has an implicit (unnamed) property that is the boolean. A Boolean object can be coerced to a boolean value.

4.3.16 String Value

   A string value is a member of the type String and is a finite ordered sequence of zero or more 16-bit unsigned integer values.
   NOTE
   Although each value usually represents a single 16-bit unit of UTF-16 text, the language does not place any restrictions or requirements on the values except that they be 16-bit unsigned integers.

4.3.17 String Type

   The type String is the set of all string values.

4.3.18 String Object

   A String object is a member of the type Object and is an instance of the built-in String object. That is, a String object is created by using the String constructor in a new expression, supplying a string as an argument. The resulting object has an implicit (unnamed) property that is the string. A String object can be coerced to a string value by calling the String constructor as a function (15.5.1).

4.3.19 Number Value

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

4.3.20 Number Type Link title

   The type Number is a set of values representing numbers. In ECMAScript, the set of values represents the double-precision 64-bit format IEEE 754 values including the special "Not-a-Number" (NaN) values, positive infinity, and negative infinity.

4.3.21 Number Object

   A Number object is a member of the type Object and is an instance of the built-in Number object. That is, a Number object is created by using the Number constructor in a new expression, supplying a number as an argument. The resulting object has an implicit (unnamed) property that is the number. A Number object can be coerced to a number value by calling the Number constructor as a function (15.7.1).

4.3.22 Infinity

   The primitive value Infinity represents the positive infinite number value. This value is a member of the Number type.

4.3.23 NaN

   The primitive value NaN represents the set of IEEE Standard "Not-a-Number" values. This value is a member of the Number type.

Revision Source

<h3 name=".D0.9E.D0.B1.D0.B7.D0.BE.D1.80"> Обзор </h3>
<p>ECMAScript это объектно-ориентированный язык для вычислений и управления объектами в host environment. Те ECMAScript не предназначен для самостоятельного использования и не имеет своей системы ввода-вывода. При этом подразумевается что система, в которую встраивается ECMAScript,обеспечивает не только базовые объекты приведенные в спецификации но и environment-specific host объекы.
</p><p><br>
</p><p>is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. ECMAScript as defined here is not intended to be computationally self-sufficient; indeed, there are no provisions in this specification for input of external data or output of computed results. Instead, it is expected that the computational environment of an ECMAScript program will provide not only the objects and other facilities described in this specification but also certain environment-specific host objects, whose description and behaviour are beyond the scope of this specification except to indicate that they may provide certain properties that can be accessed and certain functions that can be called from an ECMAScript program.
</p>
<pre class="eval">   A scripting language is a programming language that is used to manipulate, customise, 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. A scripting language is intended for use by both professional and non-professional programmers. To accommodate non-professional programmers, some aspects of the language may be somewhat less strict.
</pre>
<pre class="eval">   ECMAScript was originally designed to be a Web scripting language, providing a mechanism to enliven Web pages in browsers and to perform server computation as part of a Web-based client-server architecture. ECMAScript can provide core scripting capabilities for a variety of host environments, and therefore the core scripting language is specified in this document apart from any particular host environment.
</pre>
<pre class="eval">   Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular Java and Self, as described in:
</pre>
<pre class="eval">       * Gosling, James, Bill Joy and Guy Steele. The Java™ 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.
</pre>
<h4 name="Web_Scripting"> Web Scripting </h4>
<pre class="eval">   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.
</pre>
<pre class="eval">   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. By using browser-side and server-side scripting together, it is possible to distribute computation between the client and server while providing a customised user interface for a Web-based application.
</pre>
<pre class="eval">   Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment.
</pre>
<h4 name="Language_Overview"> Language Overview </h4>
<pre class="eval">   The following is an informal overview of ECMAScript --- not all parts of the language are described. This overview is not part of the standard proper.
</pre>
<pre class="eval">   ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. An ECMAScript object is an unordered collection of properties each with zero or more attributes that determine how each property can be used --- for example, when the ReadOnly attribute for a property is set to true, any attempt by executed ECMAScript code to change the value of the property has no effect. Properties are containers that hold other objects, primitive values, or methods. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, and String; an object is a member of the remaining built-in type Object; and a method is a function associated with an object via a property.
</pre>
<pre class="eval">   ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the Global object, the Object object, the Function object, the Array object, the String object, the Boolean object, the Number object, the Math object, the Date object, the RegExp object and the Error objects Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError.
</pre>
<pre class="eval">   ECMAScript also defines a set of built-in operators that may not be, strictly speaking, functions or methods. ECMAScript operators include various unary operations, multiplicative operators, additive operators, bitwise shift operators, relational operators, equality operators, binary bitwise operators, binary logical operators, assignment operators, and the comma operator.
</pre>
<pre class="eval">   ECMAScript syntax intentionally resembles Java syntax. ECMAScript syntax is relaxed to enable it to serve as an easy-to-use scripting language. For example, a variable is not required to have its type declared nor are types associated with properties, and defined functions are not required to have their declarations appear textually before calls to them.
</pre>
<h5 name="Objects"> Objects </h5>
<pre class="eval">   ECMAScript does not contain proper classes such as those in C++, Smalltalk, or Java, but rather, supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties. All constructors are objects, but not all objects are constructors. Each constructor has a Prototype property that is used to implement prototype-based inheritance and shared properties. Objects are created by using constructors in new expressions; for example, new String("A String") creates a new String object. Invoking a constructor without using new has consequences that depend on the constructor. For example, String("A String") produces a primitive string, not an object.
</pre>
<pre class="eval">   ECMAScript supports prototype-based inheritance. Every constructor has an associated prototype, and every object created by that constructor has an implicit reference to the prototype (called the object's prototype) associated with its constructor. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.
</pre>
<pre class="eval">   In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, and structure, behaviour, and state are all inherited.
</pre>
<pre class="eval">   All objects that do not directly contain a particular property that their prototype contains share that property and its value. The following diagram illustrates this:
   implicit prototype link explicit prototype link 15 -4
</pre>
<pre class="eval">   CF is a constructor (and also an object). Five objects have been created by using new expressions: cf1, cf2, cf3, cf4, and cf5. Each of these objects contains properties named q1 and q2. The dashed lines represent the implicit prototype relationship; so, for example, cf3's prototype is CFp. The constructor, CF, has two properties itself, named P1 and P2, which are not visible to CFp, cf1, cf2, cf3, cf4, or cf5. The property named CFP1 in CFp is shared by cf1, cf2, cf3, cf4, and cf5 (but not by CF), as are any properties found in CFp's implicit prototype chain that are not named q1, q2, or CFP1. Notice that there is no implicit prototype link between CF and CFp.
</pre>
<pre class="eval">   Unlike class-based object languages, properties can be added to objects dynamically by assigning values to them. That is, constructors are not required to name or assign values to all or any of the constructed object's properties. In the above diagram, one could add a new shared property for cf1, cf2, cf3, cf4, and cf5 by assigning a new value to the property in CFp.
</pre>
<h3 name="Definitions"> Definitions </h3>
<pre class="eval">   The following are informal definitions of key terms associated with ECMAScript.
</pre>
<h4 name="Type"> Type </h4>
<pre class="eval">   A type is a set of data values.
</pre>
<p>4.3.2 Primitive Value
</p>
<pre class="eval">   A primitive value is a member of one of the types Undefined, Null, Boolean, Number, or String. A primitive value is a datum that is represented directly at the lowest level of the language implementation.
</pre>
<p>4.3.3 Object
</p>
<pre class="eval">   An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.
</pre>
<p>4.3.4 Constructor
</p>
<pre class="eval">   A constructor is a Function object that creates and initialises objects. Each constructor has an associated prototype object that is used to implement inheritance and shared properties.
</pre>
<p>4.3.5 Prototype
</p>
<pre class="eval">   A prototype is an object used to implement structure, state, and behaviour inheritance in ECMAScript. When a constructor creates an object, that object implicitly references the constructor's associated prototype for the purpose of resolving property references. The constructor's associated prototype 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.
</pre>
<p>4.3.6 Native Object
</p>
<pre class="eval">   A native object is any object supplied by an ECMAScript implementation independent of the host environment. Standard native objects are defined in this specification. Some native objects are built-in; others may be constructed during the course of execution of an ECMAScript program.
</pre>
<p>4.3.7 Built-in Object
</p>
<pre class="eval">   A built-in object is any object supplied by an ECMAScript implementation, independent of the host environment, which is present at the start of the execution of an ECMAScript program. Standard built-in objects are defined in this specification, and an ECMAScript implementation may specify and define others. Every built-in object is a native object.
</pre>
<p>4.3.8 Host Object
</p>
<pre class="eval">   A host object is any object supplied by the host environment to complete the execution environment of ECMAScript. Any object that is not native is a host object.
</pre>
<p>4.3.9 Undefined Value
</p>
<pre class="eval">   The undefined value is a primitive value used when a variable has not been assigned a value.
</pre>
<p>4.3.10 Undefined Type
</p>
<pre class="eval">   The type Undefined has exactly one value, called undefined.
</pre>
<p>4.3.11 Null Value
</p>
<pre class="eval">   The null value is a primitive value that represents the null, empty, or non-existent reference.
</pre>
<p>4.3.12 Null Type
</p>
<pre class="eval">   The type Null has exactly one value, called null.
</pre>
<p>4.3.13 Boolean Value
</p>
<pre class="eval">   A boolean value is a member of the type Boolean and is one of two unique values, true and false.
</pre>
<p>4.3.14 Boolean Type
</p>
<pre class="eval">   The type Boolean represents a logical entity and consists of exactly two unique values. One is called true and the other is called false.
</pre>
<p>4.3.15 Boolean Object
</p>
<pre class="eval">   A Boolean object is a member of the type Object and is an instance of the built-in Boolean object. That is, a Boolean object is created by using the Boolean constructor in a new expression, supplying a boolean as an argument. The resulting object has an implicit (unnamed) property that is the boolean. A Boolean object can be coerced to a boolean value.
</pre>
<p>4.3.16 String Value
</p>
<pre class="eval">   A string value is a member of the type String and is a finite ordered sequence of zero or more 16-bit unsigned integer values.
</pre>
<pre class="eval">   NOTE
   Although each value usually represents a single 16-bit unit of UTF-16 text, the language does not place any restrictions or requirements on the values except that they be 16-bit unsigned integers.
</pre>
<p>4.3.17 String Type
</p>
<pre class="eval">   The type String is the set of all string values.
</pre>
<p>4.3.18 String Object
</p>
<pre class="eval">   A String object is a member of the type Object and is an instance of the built-in String object. That is, a String object is created by using the String constructor in a new expression, supplying a string as an argument. The resulting object has an implicit (unnamed) property that is the string. A String object can be coerced to a string value by calling the String constructor as a function (15.5.1).
</pre>
<p>4.3.19 Number Value
</p>
<pre class="eval">   A number value is a member of the type Number and is a direct representation of a number.
</pre>
<p>4.3.20 Number Type
<a href="ru/Link_title">Link title</a>
</p>
<pre class="eval">   The type Number is a set of values representing numbers. In ECMAScript, the set of values represents the double-precision 64-bit format IEEE 754 values including the special "Not-a-Number" (NaN) values, positive infinity, and negative infinity.
</pre>
<p>4.3.21 Number Object
</p>
<pre class="eval">   A Number object is a member of the type Object and is an instance of the built-in Number object. That is, a Number object is created by using the Number constructor in a new expression, supplying a number as an argument. The resulting object has an implicit (unnamed) property that is the number. A Number object can be coerced to a number value by calling the Number constructor as a function (15.7.1).
</pre>
<p>4.3.22 Infinity
</p>
<pre class="eval">   The primitive value Infinity represents the positive infinite number value. This value is a member of the Number type.
</pre>
<p>4.3.23 NaN
</p>
<pre class="eval">   The primitive value NaN represents the set of IEEE Standard "Not-a-Number" values. This value is a member of the Number type.
</pre>
Revert to this revision