ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 8

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     6      7      8      9     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 8

 

 

Batak

Batak

Batak

Batak

Batk

Batk

Bengali

Bengali

Bengali

Bengali

Beng

Beng

Bhaiksuki

Bhaiksuki

Bhaiksuki

Bhaiksuki

Bhks

Bhks

Bopomofo

Bopomofo

Bopomofo

Bopomofo

Bopo

Bopo

Brahmi

Brahmi

Brahmi

Brahmi

Brah

Brah

Braille

Braille

Braille

Braille

Brai

Brai

Buginese

Buginese

Buginese

Buginese

Bugi

Bugi

Buhid

Buhid

Buhid

Buhid

Buhd

Buhd

Canadian_Aboriginal

Canadian_Aboriginal

Canadian_Aboriginal

Canadian_Aboriginal

Cans

Cans

Carian

Carian

Carian

Carian

Cari

Cari

Caucasian_Albanian

Caucasian_Albanian

Caucasian_Albanian

Caucasian_Albanian

Aghb

Aghb

Chakma

Chakma

Chakma

Chakma

Cakm

Cakm

Cham

Cham

Cham

Cham

Chorasmian

Chorasmian

Chorasmian

Chorasmian

Chrs

Chrs

Cherokee

Cherokee

Cherokee

Cherokee

Cher

Cher

Common

Common

Common

Common

Zyyy

Zyyy

Coptic

Coptic

Coptic

Coptic

Copt

Copt

Qaac

Qaac

Cuneiform

Cuneiform

Cuneiform

Cuneiform

Xsux

Xsux

604

Cypriot

Cypriot

Cypriot

Cypriot

Cprt

Cprt

Cyrillic

Cyrillic

Cyrillic

Cyrillic

Cyrl

Cyrl

Deseret

Deseret

Deseret

Deseret

Dsrt

Dsrt

Devanagari

Devanagari

Devanagari

Devanagari

Deva

Deva

Dives_Akuru

Dives_Akuru

Dives_Akuru

Dives_Akuru

Diak

Diak

Dogra

Dogra

Dogra

Dogra

Dogr

Dogr

Duployan

Duployan

Duployan

Duployan

Dupl

Dupl

Egyptian_Hieroglyphs

Egyptian_Hieroglyphs

Egyptian_Hieroglyphs

Egyptian_Hieroglyphs

Egyp

Egyp

Elbasan

Elbasan

Elbasan

Elbasan

Elba

Elba

Elymaic

Elymaic

Elymaic

Elymaic

Elym

Elym

Ethiopic

Ethiopic

Ethiopic

Ethiopic

Ethi

Ethi

Georgian

Georgian

Georgian

Georgian

Geor

Geor

Glagolitic

Glagolitic

Glagolitic

Glagolitic

Glag

Glag

Gothic

Gothic

Gothic

Gothic

Goth

Goth

Grantha

Grantha

Grantha

Grantha

Gran

Gran

Greek

Greek

Greek

Greek

Grek

Grek

Gujarati

Gujarati

Gujarati

Gujarati

Gujr

Gujr

Gunjala_Gondi

Gunjala_Gondi

Gunjala_Gondi

Gunjala_Gondi

Gong

Gong

605

Gurmukhi

Gurmukhi

Gurmukhi

Gurmukhi

Guru

Guru

Han

Han

Han

Han

Hani

Hani

Hangul

Hangul

Hangul

Hangul

Hang

Hang

Hanifi_Rohingya

Hanifi_Rohingya

Hanifi_Rohingya

Hanifi_Rohingya

Rohg

Rohg

Hanunoo

Hanunoo

Hanunoo

Hanunoo

Hano

Hano

Hatran

Hatran

Hatran

Hatran

Hatr

Hatr

Hebrew

Hebrew

Hebrew

Hebrew

Hebr

Hebr

Hiragana

Hiragana

Hiragana

Hiragana

Hira

Hira

Imperial_Aramaic

Imperial_Aramaic

Imperial_Aramaic

Imperial_Aramaic

Armi

Armi

Inherited

Inherited

Inherited

Inherited

Zinh

Zinh

Qaai

Qaai

Inscriptional_Pahlavi

Inscriptional_Pahlavi

Inscriptional_Pahlavi

Inscriptional_Pahlavi

Phli

Phli

Inscriptional_Parthian

Inscriptional_Parthian

Inscriptional_Parthian

Inscriptional_Parthian

Prti

Prti

Javanese

Javanese

Javanese

Javanese

Java

Java

Kaithi

Kaithi

Kaithi

Kaithi

Kthi

Kthi

Kannada

Kannada

Kannada

Kannada

Knda

Knda

Katakana

Katakana

Katakana

Katakana

Kana

Kana

Kayah_Li

Kayah_Li

Kayah_Li

Kayah_Li

Kali

Kali

Kharoshthi

Kharoshthi

Kharoshthi

Kharoshthi

606

bitwise operators, binary logical operators, assignment operators, and the comma operator.

Large ECMAScript programs are supported by 

modules

 which allow a program to be divided into multiple sequences

of statements and declarations. Each module explicitly identifies declarations it uses that need to be provided by other
modules and which of its declarations are available for use by other modules.

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.

Even though ECMAScript includes syntax for class definitions, ECMAScript objects are not fundamentally class-based
such as those in C++, Smalltalk, or Java. Instead objects may be created in various ways including via a literal notation
or via 

constructors

 which create objects and then execute code that initializes all or part of them by assigning initial

values to their properties. Each 

constructor

 is a function that has a property named 

"prototype"

 that is used to

implement 

prototype-based inheritance

 and 

shared properties

. Objects are created by using constructors in 

new

expressions; for example, 

new Date(2009, 11)

new Date(2009, 11)

 creates a new Date object. Invoking a 

constructor

 without using

new

 has consequences that depend on the 

constructor

. For example, 

Date()

Date()

 produces a string representation of the

current date and time rather than an object.

Every object created by a 

constructor

 has an implicit reference (called the object's 

prototype

) to the value of its

constructor

's 

"prototype"

 property. Furthermore, a prototype may have a non-null implicit reference to its prototype,

and so on; this is called the 

prototype chain

. 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.

4.3.1  Objects

50

Figure 1: Object/Prototype Relationships

implicit prototype link

explicit prototype property

CF

prototype
P1
P2

CF

p

CFP1

q1
q2

cf

1

q1
q2

cf

2

q1
q2

cf

3

q1
q2

cf

4

q1
q2

cf

5

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, while
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. Figure 1 illustrates this:

CF

 is a 

constructor

 (and also an object). Five objects have been created by using 

new

new

 expressions: 

cf

1

cf

2

cf

3

cf

4

, and

cf

5

. Each of these objects contains properties named 

"q1"

 and 

"q2"

. The dashed lines represent the implicit prototype

relationship; so, for example, 

cf

3

's prototype is 

CF

p

. The 

constructor

CF

, has two properties itself, named 

"P1"

 and

"P2"

, which are not visible to 

CF

p

cf

1

cf

2

cf

3

cf

4

, or 

cf

5

. The property named 

"CFP1"

 in 

CF

p

 is shared by 

cf

1

cf

2

cf

3

,

cf

4

, and 

cf

5

 (but not by 

CF

), as are any properties found in 

CF

p

's implicit prototype chain that are not named 

"q1"

,

"q2"

, or 

"CFP1"

. Notice that there is no implicit prototype link between 

CF

 and 

CF

p

.

Unlike most 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 

cf

1

cf

2

cf

3

cf

4

, and 

cf

5

 by assigning a new value to the

property in 

CF

p

.

Although ECMAScript objects are not inherently class-based, it is often convenient to define class-like abstractions
based upon a common pattern of 

constructor

 functions, prototype objects, and methods. The ECMAScript built-in

objects themselves follow such a class-like pattern. Beginning with ECMAScript 2015, the ECMAScript language
includes syntactic class definitions that permit programmers to concisely define objects that conform to the same class-
like abstraction pattern used by the built-in objects.

4.3.2  The Strict Variant of ECMAScript

51

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

The strict variant of ECMAScript is commonly referred to as the 

strict mode

 of the language. Strict mode selection and

use of the strict mode syntax and semantics of ECMAScript is explicitly made at the level of individual ECMAScript
source text units as described in 

11.2.2

. Because strict mode is selected at the level of a syntactic source text unit, strict

mode only imposes restrictions that have local effect within such a source text unit. Strict mode does not restrict or
modify any aspect of the ECMAScript semantics that must operate consistently across multiple source text units. A
complete ECMAScript program may be composed of both strict mode and non-strict mode ECMAScript source text
units. In this case, strict mode only applies when actually executing code that is defined within a strict mode source
text unit.

In order to conform to this specification, an ECMAScript implementation must implement both the full unrestricted
ECMAScript language and the strict variant of the ECMAScript language as defined by this specification. In addition,
an implementation must support the combination of unrestricted and strict mode source text units into a single
composite program.

For the purposes of this document, the following terms and definitions apply.

an 

implementation-approximated

 facility is defined in whole or in part by an external source but has a recommended,

ideal behaviour in this specification

an 

implementation-defined

 facility is defined in whole or in part by an external source to this specification

same as 

implementation-defined

NOTE

set of data values as defined in clause 

6

Editorially, see clause 

4.2

.

4.4  Terms and Definitions

4.4.1  implementation-approximated

4.4.2  implementation-defined

4.4.3  host-defined

4.4.4  type

4.4.5  primitive value

52

member of one of the types Undefined, Null, Boolean, Number, BigInt, Symbol, or String as defined in clause 

6

NOTE

member of the type Object

NOTE

function object

 that creates and initializes objects

NOTE

object that provides shared properties for other objects

NOTE

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

object that does not have the default behaviour for one or more of the essential internal methods

NOTE

object whose semantics are defined by this specification

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

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

The value of a 

constructor

's 

"prototype"

 property is a prototype object that is used to implement

inheritance and shared properties.

When a 

constructor

 creates an object, that object implicitly references the 

constructor

's

"prototype"

 property for the purpose of resolving property references. The 

constructor

's

"prototype"

 property can be referenced by the program expression

constructor

constructor

.prototype

.prototype

, and properties added to an object's prototype are shared,

through inheritance, by all objects sharing the prototype. Alternatively, a new object may be
created with an explicitly specified prototype by using the 

Object.create

Object.create

 built-in function.

Any object that is not an 

ordinary object

 is an 

exotic object

.

4.4.6  object

4.4.7  constructor

4.4.8  prototype

4.4.9  ordinary object

4.4.10  exotic object

4.4.11  standard object

53

 

 

 

 

 

 

 

Content      ..     6      7      8      9     ..