Function definition

Syntax

    FunctionDefinition :
      function FunctionName TypeParametersopt FunctionCommonallowIn

Function name

Syntax

    FunctionName :
      IdentifierName
      get [no line break] IdentifierName
      set [no line break] IdentifierName

FunctionName is used inside FunctionDefinition.

function f(): void {}
function get x(): Number (impl.x)
function set x(v: Number): void { impl.x = v }

TypeParameters may not appear in a function definition defining a getter, setter or constructor.

Function body

Syntax

function f():Number 10

function f():void {
    // code
}
    FunctionCommonβ :
      FunctionSignature
      FunctionSignature [lookahead ∉ { { }] [inline, or in a greater indentation, or lookahead = **(**] AssignmentExpressionβ
      FunctionSignature Block

Function signature

Syntax

    FunctionSignature :
      ( Parameters ) ResultType
    ResultType :
      «empty»
      : TypeExpression

Parameter list

Syntax

    Parameters :
      «empty»
      NonemptyParameters
    NonemptyParameters :
      Parameter
      Parameter , NonemptyParameters
      RestParameter
    Parameter :
      TypedPattern
      TypedPattern = AssignmentExpressionallowIn
    RestParameter :
      ... TypedPattern