ECMAScript 4 Netscape Proposal
Core Language
Statements
|
Wednesday, June 4, 2003
Most of the behavior of statements is the same as in ECMAScript 3. 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.
The super
statement calls the superclass’s constructor. It can
only be used inside a class’s constructor.
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 ForInitializer
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.
A return
statement can only be used inside a function or constructor.
The return
statement cannot have an expression if used inside a constructor
or a setter.
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 b; 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 {} } }
Waldemar Horwat Last modified Wednesday, June 4, 2003 |