April 2002 Draft
JavaScript 2.0
Core Language
Statements
|
Wednesday, February 20, 2002
Most of the behavior of statements is the same as in JavaScript 1.5. Differences are highlighted below.
;
;
A Substatement is a statement directly contained by one of the compound
statements label:
, if
, switch
, while
, do while
,
for
, or with
(but not a block). A substatement cannot be a directive except
that, in non-strict mode only, it can be a var
definition without attributes or types.
A substatement can also consist of one or more attributes applied to a group of substatements
enclosed in braces. The attributes must evaluate to either true
or false
. The braces do not form
a scope in this case.
The Semicolon productions allow both grammatical and line-break semicolon insertion.
Under some circumstances an ExpressionStatement is treated as a constructor call instead of an expression to be evaluated. See calling a superconstructor.
The super
statement calls the superclass’s default constructor. It
can only be used inside a class’s constructor. There are also other ways of calling a specific constructor in the superclass
or in the current class; see calling a superconstructor.
A block groups statements and forms a scope.
The semicolon is optional before the else
.
The semicolon is optional before the closing while
.
A for
statement forms a scope. Any definitions in it (including the ForInitialiser
and ForInBinding) are visible inside the for
statement and its
substatement, but not outside the for
statement. However, a var
definition inside a for
statement may be hoisted to the nearest enclosing regional scope.
Each CatchClause forms a scope. The Parameter, if any, is defined as a local variable visible only within the CatchClause.
The Blocks following try
and finally
are also scopes
like other Block statements.
Attributes can be applied to a group of directives
by following them by a {
, the directives, and a }
. The attributes apply to all of the enclosed directives.
The attribute true
is ignored. The attribute false
causes all of the enclosed directives to be omitted.
When used this way, the braces do not form a block or a scope.
Annotated groups are useful to define several items without having to repeat attributes for each one. For example,
class foo { var z:Integer; public var a; private var a; private function f() {} private function g(x:Integer):Boolean {} }
is equivalent to:
class foo { var z:Integer; public var a; private { var b; function f() {} function g(x:Integer):Boolean {} } }
An include
directive includes a JavaScript source file at the current position. The interpretation of String
is implementation-defined but recommended to be similar to the interpretation of a string in an import
directive.
The included file should contain a syntactically balanced JavaScript program that is processed before processing the
rest of the program that contains the include
directive.
Waldemar Horwat Last modified Wednesday, February 20, 2002 |