1、 Reference number ISO/IEC 16262:2011(E) ISO/IEC 2011INTERNATIONAL STANDARD ISO/IEC 16262 Third edition 2011-06.15 Information technology Programming languages, their environments and system software interfaces ECMAScript language specification Technologies de linformation Langages de programmation,
2、leurs environnements et interfaces de logiciel systme Spcification du langage ECMAscript ISO/IEC 16262:2011(E) COPYRIGHT PROTECTED DOCUMENT ISO/IEC 2011 All rights reserved. Unless otherwise specif ied, no part of this publication may be reproduced or utilized in any form or by an y means, electroni
3、c or mechanical, including photocopying and microfilm, w ithout permission in wr iting from either ISO at the address be low or ISOs member body in the country of the requester. ISO copyright office Case postale 56 CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail copyrightiso.or
4、g Web www.iso.org Published in Switzerland ii ISO/IEC 2011 All rights reservedISO/IEC 16262:2011(E) ISO/IEC 2011 All rights reserved iiiContents Page Foreword .viii Introduction.ix 1 Scope .1 2 Conformance .1 3 Normative references. 1 4 Overview. .1 4.1 Web Scripting 2 4.2 Language Overview 2 4.2.1
5、Objects .3 4.2.2 The Strict Variant of ECMAScript 4 4.3 Terms and definitions.4 5 Notational Conventions. .8 5.1 Syntactic and Lexical Grammars.8 5.1.1 Context-Free Grammars .8 5.1.2 The Lexical and RegExp Grammars 8 5.1.3 The Numeric String Grammar 8 5.1.4 The Syntactic Grammar8 5.1.5 The JSON Gram
6、mar. .9 5.1.6 Grammar Notation. .9 5.2 Algorithm Conventions 12 6 Source Text .13 7 Lexical Conventions .14 7.1 Unicode Format-Control Characters .14 7.2 White Space .15 7.3 Line Terminators. 15 7.4 Comments. 16 7.5 Tokens. 17 7.6 Identifier Names and Identifiers.17 7.6.1 Reserved Words. .18 7.7 Pun
7、ctuators .19 7.8 Literals. 20 7.8.1 Null Literals .20 7.8.2 Boolean Literals. .20 7.8.3 Numeric Literals. .20 7.8.4 String Literals 22 7.8.5 Regular Expression Literals.25 7.9 Automatic Semicolon Insertion .26 7.9.1 Rules of Automatic Semicolon Insertion 26 7.9.2 Examples of Automatic Semicolon Inse
8、rtion27 8 Types .28 8.1 The Undefined Type28 8.2 The Null Type 28 8.3 The Boolean Type. 29 8.4 The String Type.29 8.5 The Number Type 29 8.6 The Object Type 30 8.6.1 Property Attributes .30 8.6.2 Object Internal Properties and Methods .31 ISO/IEC 16262:2011(E) iv ISO/IEC 2011 All rights reserved8.7
9、The Reference Specification Type.35 8.7.1 GetValue (V). 35 8.7.2 PutValue (V, W) .36 8.8 The List Specification Type36 8.9 The Completion Specification Type.36 8.10 The Property Descriptor and Property Identifier Specification Types37 8.10.1 IsAccessorDescriptor ( Desc ) .37 8.10.2 IsDataDescriptor
10、( Desc )37 8.10.3 IsGenericDescriptor ( Desc )37 8.10.4 FromPropertyDescriptor ( Desc ). 38 8.10.5 ToPropertyDescriptor ( Obj )38 8.11 The Lexical Environment and Environment Record Specification Types 39 8.12 Algorithms for Object Internal Methods39 8.12.1 GetOwnProperty (P) .39 8.12.2 GetProperty
11、(P). 39 8.12.3 Get (P). 39 8.12.4 CanPut (P) .39 8.12.5 Put ( P, V, Throw ).40 8.12.6 HasProperty (P). .40 8.12.7 Delete (P, Throw)41 8.12.8 DefaultValue (hint). .41 8.12.9 DefineOwnProperty (P, Desc, Throw) .41 9 Type Conversion and Testing 43 9.1 ToPrimitive 43 9.2 ToBoolean .43 9.3 ToNumber. .43
12、9.3.1 ToNumber Applied to the String Type.44 9.4 ToInteger 46 9.5 ToInt32: (Signed 32 Bit Integer) .47 9.6 ToUint32: (Unsigned 32 Bit Integer) 47 9.7 ToUint16: (Unsigned 16 Bit Integer) 47 9.8 ToString. 48 9.8.1 ToString Applied to the Number Type.48 9.9 ToObject. .49 9.10 CheckObjectCoercible 49 9.
13、11 IsCallable .49 9.12 The SameValue Algorithm. .50 10 Executable Code and Execution Contexts50 10.1 Types of Executable Code50 10.1.1 Strict Mode Code.51 10.2 Lexical Environments .51 10.2.1 Environment Records. 51 10.2.2 Lexical Environment Operations .56 10.2.3 The Global Environment .56 10.3 Exe
14、cution Contexts .56 10.3.1 Identifier Resolution. 57 10.4 Establishing an Execution Context .57 10.4.1 Entering Global Code .58 10.4.2 Entering Eval Code .58 10.4.3 Entering Function Code .58 10.5 Declaration Binding Instantiation. .59 10.6 Arguments Object .60 11 Expressions. 63 11.1 Primary Expres
15、sions. .63 11.1.1 The this Keyword63 11.1.2 Identifier Reference .63 11.1.3 Literal Reference. 63 11.1.4 Array Initialiser. .63 ISO/IEC 16262:2011(E) ISO/IEC 2011 All rights reserved v11.1.5 Object Initialiser 65 11.1.6 The Grouping Operator 67 11.2 Left-Hand-Side Expressions 67 11.2.1 Property Acce
16、ssors 67 11.2.2 The new Operator68 11.2.3 Function Calls .68 11.2.4 Argument Lists 69 11.2.5 Function Expressions .69 11.3 Postfix Expressions. .69 11.3.1 Postfix Increment Operator70 11.3.2 Postfix Decrement Operator.70 11.4 Unary Operators. .70 11.4.1 The delete Operator70 11.4.2 The void Operator
17、71 11.4.3 The typeof Operator71 11.4.4 Prefix Increment Operator. .71 11.4.5 Prefix Decrement Operator 72 11.4.6 Unary + Operator 72 11.4.7 Unary - Operator 72 11.4.8 Bitwise NOT Operator ( ) .72 11.4.9 Logical NOT Operator ( ! ) .73 11.5 Multiplicative Operators .73 11.5.1 Applying the * Operator .
18、73 11.5.2 Applying the / Operator .74 11.5.3 Applying the % Operator .74 11.6 Additive Operators 75 11.6.1 The Addition operator ( + ) .75 11.6.2 The Subtraction Operator ( - ) .75 11.6.3 Applying the Additive Operators to Numbers.75 11.7 Bitwise Shift Operators. .76 11.7.1 The Left Shift Operator (
19、 ) 76 11.7.3 The Unsigned Right Shift Operator ( )77 11.8 Relational Operators .77 11.8.1 The Less-than Operator ( )78 11.8.3 The Less-than-or-equal Operator ( = ) 78 11.8.5 The Abstract Relational Comparison Algorithm.78 11.8.6 The instanceof operator .79 11.8.7 The in operator79 11.9 Equality Oper
20、ators 80 11.9.1 The Equals Operator ( = ) .80 11.9.2 The Does-not-equals Operator ( != ) .80 11.9.3 The Abstract Equality Comparison Algorithm80 11.9.4 The Strict Equals Operator ( = ).81 11.9.5 The Strict Does-not-equal Operator ( != ).81 11.9.6 The Strict Equality Comparison Algorithm .82 11.10 Bi
21、nary Bitwise Operators .82 11.11 Binary Logical Operators .83 11.12 Conditional Operator ( ? : ) 84 11.13 Assignment Operators. 84 11.13.1 Simple Assignment ( = ) .85 11.13.2 Compound Assignment ( op= )85 11.14 Comma Operator ( , ).85 12 Statements .86 12.1 Block. .86 ISO/IEC 16262:2011(E) vi ISO/IE
22、C 2011 All rights reserved12.2 Variable Statement 87 12.2.1 Strict Mode Restrictions.88 12.3 Empty Statement. 88 12.4 Expression Statement 89 12.5 The if Statement89 12.6 Iteration Statements 89 12.6.1 The do-while Statement 90 12.6.2 The while Statement90 12.6.3 The for Statement90 12.6.4 The for-i
23、n Statement 91 12.7 The continue Statement .92 12.8 The break Statement93 12.9 The return Statement .93 12.10 The with Statement93 12.10.1 Strict Mode Restrictions.94 12.11 The switch Statement .94 12.12 Labelled Statements .96 12.13 The throw Statement96 12.14 The try Statement96 12.14.1 Strict Mod
24、e Restrictions.97 12.15 The debugger statement97 13 Function Definition. 98 13.1 Strict Mode Restrictions.99 13.2 Creating Function Objects .99 13.2.1 Call 100 13.2.2 Construct. .100 13.2.3 The ThrowTypeError Function Object 100 14 Program. 101 14.1 Directive Prologues and the Use Strict Directive .
25、101 15 Standard Built-in ECMAScript Objects102 15.1 The Global Object. 103 15.1.1 Value Properties of the Global Object .103 15.1.2 Function Properties of the Global Object104 15.1.3 URI Handling Function Properties. 105 15.1.4 Constructor Properties of the Global Object 110 15.1.5 Other Properties
26、of the Global Object .111 15.2 Object Objects .111 15.2.1 The Object Constructor Called as a Function.111 15.2.2 The Object Constructor 112 15.2.3 Properties of the Object Constructor 112 15.2.4 Properties of the Object Prototype Object115 15.2.5 Properties of Object Instances 117 15.3 Function Obje
27、cts .117 15.3.1 The Function Constructor Called as a Function.117 15.3.2 The Function Constructor 117 15.3.3 Properties of the Function Constructor 118 15.3.4 Properties of the Function Prototype Object118 15.3.5 Properties of Function Instances.121 15.4 Array Objects. .122 15.4.1 The Array Construc
28、tor Called as a Function 122 15.4.2 The Array Constructor123 15.4.3 Properties of the Array Constructor123 15.4.4 Properties of the Array Prototype Object124 15.4.5 Properties of Array Instances 140 15.5 String Objects .141 15.5.1 The String Constructor Called as a Function .141 15.5.2 The String Co
29、nstructor. 142 ISO/IEC 16262:2011(E) ISO/IEC 2011 All rights reserved vii15.5.3 Properties of the String Constructor.142 15.5.4 Properties of the String Prototype Object.142 15.5.5 Properties of String Instances .152 15.6 Boolean Objects. .152 15.6.1 The Boolean Constructor Called as a Function152 1
30、5.6.2 The Boolean Constructor. 152 15.6.3 Properties of the Boolean Constructor .153 15.6.4 Properties of the Boolean Prototype Object.153 15.6.5 Properties of Boolean Instances .154 15.7 Number Objects 154 15.7.1 The Number Constructor Called as a Function 154 15.7.2 The Number Constructor 154 15.7
31、.3 Properties of the Number Constructor154 15.7.4 Properties of the Number Prototype Object155 15.7.5 Properties of Number Instances 159 15.8 The Math Object. .159 15.8.1 Value Properties of the Math Object159 15.8.2 Function Properties of the Math Object 161 15.9 Date Objects 165 15.9.1 Overview of
32、 Date Objects and Definitions of Abstract Operators.165 15.9.2 The Date Constructor Called as a Function171 15.9.3 The Date Constructor .171 15.9.4 Properties of the Date Constructor172 15.9.5 Properties of the Date Prototype Object .173 15.9.6 Properties of Date Instances181 15.10 RegExp (Regular E
33、xpression) Objects181 15.10.1 Patterns .181 15.10.2 Pattern Semantics.183 15.10.3 The RegExp Constructor Called as a Function 195 15.10.4 The RegExp Constructor195 15.10.5 Properties of the RegExp Constructor196 15.10.6 Properties of the RegExp Prototype Object196 15.10.7 Properties of RegExp Instan
34、ces 198 15.11 Error Objects .198 15.11.1 The Error Constructor Called as a Function.199 15.11.2 The Error Constructor 199 15.11.3 Properties of the Error Constructor.199 15.11.4 Properties of the Error Prototype Object 199 15.11.5 Properties of Error Instances.200 15.11.6 Native Error Types Used in
35、This Standard200 15.11.7 NativeError Object Structure201 15.12 The JSON Object .203 15.12.1 The JSON Grammar203 15.12.2 parse ( text , reviver )204 15.12.3 stringify ( value , replacer , space ).206 16 Errors .209 Annex A (informative) Grammar Summary 211 Annex B (informative) Compatibility.230 Anne
36、x C (informative) The Strict Mode of ECMAScript.234 Annex D (informative) Corrections and Clarifications in the 3 rdEdition with Possible 2 ndEdition Compatibility Impact236 Annex E (informative) Additions and Changes in the 3 rdEdition that Introduce Incompatibilities with the 2 ndEdition 237 Bibli
37、ography.240 ISO/IEC 16262:2011(E) viii ISO/IEC 2011 All rights reservedForeword ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC p
38、articipate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual in terest. Other international organizations, govern
39、mental and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Par
40、t 2. The main task of the joint technical committee is to prepare International Standards. Draft International Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an International Standard requires approval by at least 75 % of the national
41、bodies casting a vote. Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. ISO/IEC 16262 was prepared by Ecma International (as ECMA-262) and was
42、 adopted, under a special “fast- track procedure”, by Joint Technical Committee ISO/IEC JTC 1, Information technology, in parallel with its approval by national bodies of ISO and IEC. This third edition cancels and replaces the second edition (ISO/IEC 16262:2002), which has been technically revised.
43、 ISO/IEC 16262:2011(E) ISO/IEC 2011 All rights reserved ixIntroduction This International Standard is based on several or iginating technologies, the most well-known being JavaScript (Netscape) and JScr ipt (Microsoft). The lang uage was invented by Bren dan Eich at Netscape and first a ppeared in t
44、hat companys Navigator 2.0 browser. It has appeared in all subsequent browsers from Netscape and in all browse rs from Microsoft starting with Internet Explorer 3.0. The development of this Internation al Standard start ed in November 1996. The first editi on of this International Standard was adopt
45、ed by the Ecma General Assembly of June 1997. That International Standard was submitted to IS O/IEC JTC 1 for ad option under the fast-track procedure, and approved as ISO/IEC 16262, first edition, in April 1998. The second edition of this International Standard introduced powerful regular expressio
46、ns, better string handling, new control statements, try/catch exception handling, tighter definition of errors, formattin g for numeric output and mi nor changes in anticipatio n of forthcoming internat ionalization facilities and future language growth. The second edition of the ECMAScript standard
47、 was published as ISO/IEC 16262 in June 2002. Since publication of the second edition of ISO/IE C 16262:2002, ECMAScript has achieved massive adoption in conjunction with the World Wide Web where it has become the programming language that is supported by essentially all web browsers. Significant wo
48、rk was done to develop a third edition of ECMAScript. Although that wo rk was not co mpleted and not publi shed as a n ew edition of ECMAScript, it informs continuin g evolution of the language. The present third edition of ISO/IEC 16262 (published as ECMA-262 5th edition) codifies de facto interpre
49、tations of the l anguage specification that have become common among br owser implementations and adds support for new features that have emerged since th e publication of the third edition. Such features include accessor properties, reflective cre ation and i nspection of objects, program control of prop erty attributes, additional array manipulation functions, support fo r the JSON o bject encoding format, and a strict mode that provides enhanced error checking and program sec