Ecmascript Language Specification




старонка1/44
Дата канвертавання19.04.2016
Памер1.22 Mb.
  1   2   3   4   5   6   7   8   9   ...   44

ECMAScript Language Specification Edition 3 19-Apr-16


Edition 3 Final

ECMAScript Language Specification

19 April 2016

Brief History

This ECMA Standard is based on several originating technologies, the most well known being JavaScript (Netscape) and JScript (Microsoft). The language was invented by Brendan Eich at Netscape and first appeared in that company’s Navigator 2.0 browser. It has appeared in all subsequent browsers from Netscape and in all browsers from Microsoft starting with Internet Explorer 3.0.

The development of this Standard started in November 1996. The first edition of this ECMA Standard was adopted by the ECMA General Assembly of June 1997.

That ECMA Standard was submitted to ISO/IEC JTC 1 for adoption under the fast-track procedure, and approved as international standard ISO/IEC 16262, in April 1998. The ECMA General Assembly of June 1998 approved the second edition of ECMA-262 to keep it fully aligned with ISO/IEC 16262. Changes between the first and the second edition are editorial in nature.

The current document defines the third edition of the Standard and includes powerful regular expressions, better string handling, new control statements, try/catch exception handling, tighter definition of errors, formatting for numeric output and minor changes in anticipation of forthcoming internationalisation facilities and future language growth.

Work on the language is not complete. The technical committee is working on significant enhancements, including mechanisms for scripts to be created and used across the Internet, and tighter coordination with other standards bodies such as groups within the World Wide Web Consortium and the Wireless Application Protocol Forum.

This Standard has been adopted as 3rd Edition of ECMA-262 by the ECMA General Assembly in December, 1999.

The following people have contributed to the work leading to ECMA 262:



Mike Ang

Christine Begle

Norris Boyd

Carl Cargill

Andrew Clinick

Donna Converse

Mike Cowlishaw

Chris Dollin

Jeff Dyer

Brendan Eich

Chris Espinosa

Gary Fisher

Richard Gabriel

Michael Gardner

Bill Gibbons

Richard Gillam

Waldemar Horwat

Shon Katzenberg

Cedric Krumbein

Mike Ksar

Roger Lawrence

Steve Leach

Clayton Lewis

Drew Lytle

Bob Mathis

Karl Matzke

Mike McCabe

Tom McFarland

Anh Nguyen

Brent Noorda

Andy Palay

Dave Raggett

Gary Robinson

Sam Ruby


Dario Russi

David Singer

Randy Solton

Guy Steele

Michael Turyn

Herman Venter

George Wilingmyre

Scott Wiltamuth

Rok Yu


Table of contents


1 Scope 1

2 Conformance 1

3 Normative References 1

4 Overview 3

4.1 Web Scripting 3

4.2 Language Overview 3

4.2.1 Objects 4

4.3 Definitions 5

4.3.1 Type 5

4.3.2 Primitive Value 5

4.3.3 Object 5

4.3.4 Constructor 5

4.3.5 Prototype 5

4.3.6 Native Object 5

4.3.7 Built-in Object 5

4.3.8 Host Object 5

4.3.9 Undefined Value 6

4.3.10 Undefined Type 6

4.3.11 Null Value 6

4.3.12 Null Type 6

4.3.13 Boolean Value 6

4.3.14 Boolean Type 6

4.3.15 Boolean Object 6

4.3.16 String Value 6

4.3.17 String Type 6

4.3.18 String Object 6

4.3.19 Number Value 6

4.3.20 Number Type 6

4.3.21 Number Object 7

4.3.22 Infinity 7

4.3.23 NaN 7



5 Notational Conventions 9

5.1 Syntactic and Lexical Grammars 9

5.1.1 Context-Free Grammars 9

5.1.2 The Lexical and RegExp Grammars 9

5.1.3 The Numeric String Grammar 9

5.1.4 The Syntactic Grammar 9

5.1.5 Grammar Notation 10

5.2 Algorithm Conventions 12



6 Source Text 15

7 Lexical Conventions 17

7.1 Unicode Format-Control Characters 17

7.2 White Space 17

7.3 Line Terminators 18

7.4 Comments 18

7.5 Tokens 19

7.5.1 Reserved Words 19

7.5.2 Keywords 19

7.5.3 Future Reserved Words 20

7.6 Identifiers 20

7.7 Punctuators 21

7.8 Literals 21

7.8.1 Null Literals 21

7.8.2 Boolean Literals 22

7.8.3 Numeric Literals 22

7.8.4 String Literals 24

7.8.5 Regular Expression Literals 26

7.9 Automatic Semicolon Insertion 27

7.9.1 Rules of Automatic Semicolon Insertion 27

7.9.2 Examples of Automatic Semicolon Insertion 28



8 Types 31

8.1 The Undefined Type 31

8.2 The Null Type 31

8.3 The Boolean Type 31

8.4 The String Type 31

8.5 The Number Type 31

8.6 The Object Type 32

8.6.1 Property Attributes 32

8.6.2 Internal Properties and Methods 33

8.7 The Reference Type 35

8.7.1 GetValue (V) 36

8.7.2 PutValue (V, W) 36

8.8 The List Type 36

8.9 The Completion Type 36



9 Type Conversion 37

9.1 ToPrimitive 37

9.2 ToBoolean 37

9.3 ToNumber 37

9.3.1 ToNumber Applied to the String Type 38

9.4 ToInteger 40

9.5 ToInt32: (Signed 32 Bit Integer) 40

9.6 ToUint32: (Unsigned 32 Bit Integer) 41

9.7 ToUint16: (Unsigned 16 Bit Integer) 41

9.8 ToString 41

9.8.1 ToString Applied to the Number Type 42

9.9 ToObject 43



10 Execution Contexts 45

10.1 Definitions 45

10.1.1 Function Objects 45

10.1.2 Types of Executable Code 45

10.1.3 Variable Instantiation 45

10.1.4 Scope Chain and Identifier Resolution 46

10.1.5 Global Object 46

10.1.6 Activation Object 46

10.1.7 This 47

10.1.8 Arguments Object 47

10.2 Entering An Execution Context 47

10.2.1 Global Code 47

10.2.2 Eval Code 47

10.2.3 Function Code 47



11 Expressions 49

11.1 Primary Expressions 49

11.1.1 The this Keyword 49

11.1.2 Identifier Reference 49

11.1.3 Literal Reference 49

11.1.4 Array Initialiser 49

11.1.5 Object Initialiser 50

11.1.6 The Grouping Operator 51

11.2 Left-Hand-Side Expressions 51

11.2.1 Property Accessors 52

11.2.2 The new Operator 53

11.2.3 Function Calls 53

11.2.4 Argument Lists 53

11.2.5 Function Expressions 54

11.3 Postfix Expressions 54

11.3.1 Postfix Increment Operator 54

11.3.2 Postfix Decrement Operator 54

11.4 Unary Operators 54

11.4.1 The delete Operator 55

11.4.2 The void Operator 55

11.4.3 The typeof Operator 55

11.4.4 Prefix Increment Operator 55

11.4.5 Prefix Decrement Operator 56

11.4.6 Unary + Operator 56

11.4.7 Unary - Operator 56

11.4.8 Bitwise NOT Operator ( ~ ) 56

11.4.9 Logical NOT Operator ( ! ) 56

11.5 Multiplicative Operators 57

11.5.1 Applying the * Operator 57

11.5.2 Applying the / Operator 57

11.5.3 Applying the % Operator 58

11.6 Additive Operators 58

11.6.1 The Addition operator ( + ) 58

11.6.2 The Subtraction Operator ( - ) 59

11.6.3 Applying the Additive Operators ( +,- ) to Numbers 59

11.7 Bitwise Shift Operators 59

11.7.1 The Left Shift Operator ( << ) 60

11.7.2 The Signed Right Shift Operator ( >> ) 60

11.7.3 The Unsigned Right Shift Operator ( >>> ) 60

11.8 Relational Operators 60

11.8.1 The Less-than Operator ( < ) 61

11.8.2 The Greater-than Operator ( > ) 61

11.8.3 The Less-than-or-equal Operator ( <= ) 61

11.8.4 The Greater-than-or-equal Operator ( >= ) 62

11.8.5 The Abstract Relational Comparison Algorithm 62

11.8.6 The instanceof operator 62

11.8.7 The in operator 62

11.9 Equality Operators 63

11.9.1 The Equals Operator ( == ) 63

11.9.2 The Does-not-equals Operator ( != ) 63

11.9.3 The Abstract Equality Comparison Algorithm 64

11.9.4 The Strict Equals Operator ( === ) 64

11.9.5 The Strict Does-not-equal Operator ( !== ) 65

11.9.6 The Strict Equality Comparison Algorithm 65

11.10 Binary Bitwise Operators 65

11.11 Binary Logical Operators 66

11.12 Conditional Operator ( ?: ) 67

11.13 Assignment Operators 67

11.13.1 Simple Assignment ( = ) 68

11.13.2 Compound Assignment ( op= ) 68

11.14 Comma Operator ( , ) 68

12 Statements 69

12.1 Block 69

12.2 Variable statement 70

12.3 Empty Statement 71

12.4 Expression Statement 71

12.5 The if Statement 71

12.6 Iteration Statements 72

12.6.1 The do-while Statement 72

12.6.2 The while statement 72

12.6.3 The for Statement 73

12.6.4 The for-in Statement 73

12.7 The continue Statement 74

12.8 The break Statement 75

12.9 The return Statement 75

12.10 The with Statement 75

12.11 The switch Statement 76

12.12 Labelled Statements 77

12.13 The throw statement 77

12.14 The try statement 77

13 Function Definition 79

13.1 Definitions 79

13.1.1 Equated Grammar Productions 80

13.1.2 Joined Objects 80

13.2 Creating Function Objects 80

13.2.1 [[Call]] 81

13.2.2 [[Construct]] 81

14 Program 83

15 Native ECMAScript Objects 85

15.1 The Global Object 85

15.1.1 Value Properties of the Global Object 86

15.1.2 Function Properties of the Global Object 86

15.1.3 URI Handling Function Properties 87

15.1.4 Constructor Properties of the Global Object 91

15.1.5 Other Properties of the Global Object 92

15.2 Object Objects 92

15.2.1 The Object Constructor Called as a Function 92

15.2.2 The Object Constructor 92

15.2.3 Properties of the Object Constructor 93

15.2.4 Properties of the Object Prototype Object 93

15.2.5 Properties of Object Instances 94

15.3 Function Objects 94

15.3.1 The Function Constructor Called as a Function 94

15.3.2 The Function Constructor 94

15.3.3 Properties of the Function Constructor 95

15.3.4 Properties of the Function Prototype Object 95

15.3.5 Properties of Function Instances 96

15.4 Array Objects 96

15.4.1 The Array Constructor Called as a Function 97

15.4.2 The Array Constructor 97

15.4.3 Properties of the Array Constructor 97

15.4.4 Properties of the Array Prototype Object 98

15.4.5 Properties of Array Instances 105

15.5 String Objects 106

15.5.1 The String Constructor Called as a Function 106

15.5.2 The String Constructor 106

15.5.3 Properties of the String Constructor 106

15.5.4 Properties of the String Prototype Object 107

15.5.5 Properties of String Instances 114

15.6 Boolean Objects 114

15.6.1 The Boolean Constructor Called as a Function 114

15.6.2 The Boolean Constructor 114

15.6.3 Properties of the Boolean Constructor 114

15.6.4 Properties of the Boolean Prototype Object 114

15.6.5 Properties of Boolean Instances 115

15.7 Number Objects 115

15.7.1 The Number Constructor Called as a Function 115

15.7.2 The Number Constructor 115

15.7.3 Properties of the Number Constructor 115

15.7.4 Properties of the Number Prototype Object 116

15.7.5 Properties of Number Instances 119

15.8 The Math Object 119

15.8.1 Value Properties of the Math Object 119

15.8.2 Function Properties of the Math Object 120

15.9 Date Objects 125

15.9.1 Overview of Date Objects and Definitions of Internal Operators 125

15.9.2 The Date Constructor Called as a Function 129

15.9.3 The Date Constructor 129

15.9.4 Properties of the Date Constructor 130

15.9.5 Properties of the Date Prototype Object 131

15.9.6 Properties of Date Instances 137

15.10 RegExp (Regular Expression) Objects 137

15.10.1 Patterns 137

15.10.2 Pattern Semantics 139

15.10.3 The RegExp Constructor Called as a Function 151

15.10.4 The RegExp Constructor 151

15.10.5 Properties of the RegExp Constructor 152

15.10.6 Properties of the RegExp Prototype Object 152

15.10.7 Properties of RegExp Instances 153

15.11 Error Objects 153

15.11.1 The Error Constructor Called as a Function 154

15.11.2 The Error Constructor 154

15.11.3 Properties of the Error Constructor 154

15.11.4 Properties of the Error Prototype Object 154

15.11.5 Properties of Error Instances 155

15.11.6 Native Error Types Used in This Standard 155

15.11.7 NativeError Object Structure 155

16 Errors 157

A Grammar Summary 159

A.1 Lexical Grammar 159

A.2 Number Conversions 164

A.3 Expressions 165

A.4 Statements 169

A.5 Functions and Programs 171

A.6 Universal Resource Identifier Character Classes 171

A.7 Regular Expressions 172



B Compatibility 175

B.1 Additional Syntax 175

B.1.1 Numeric Literals 175

B.1.2 String Literals 175

B.2 Additional Properties 176

B.2.1 escape (string) 176

B.2.2 unescape (string) 177

B.2.3 String.prototype.substr (start, length) 177

B.2.4 Date.prototype.getYear ( ) 178

B.2.5 Date.prototype.setYear (year) 178

B.2.6 Date.prototype.toGMTString ( ) 178




  1   2   3   4   5   6   7   8   9   ...   44


База данных защищена авторским правом ©shkola.of.by 2016
звярнуцца да адміністрацыі

    Галоўная старонка