Skip to content

13 Function Definition

Syntax

FunctionDeclaration :
function Identifier ( FormalParameterListopt ) Block
FormalParameterList :
Identifier
FormalParameterList , Identifier

Semantics

Defines a property of the global object whose name is the Identifier following the function keyword and whose value is a function object with the given parameter list and statements. If the function definition is supplied text to the eval function and the calling context has an activation object, then the declared function is added to the activation object instead of to the global object. See section 10.1.3.

The production FunctionDeclaration : function Identifier ( ) Block is processed for function declarations as follows:

  1. Create a new Function object (15.3.2.1) with no parameters, the Block as the body, and Identifier as its name.
  2. Put this new Function object as the new value of the property named Identifier in the global object or the activation object, as appropriate (see above).

The production FunctionDeclaration : function Identifier ( FormalParameterList ) Block is processed for function declarations as follows:

  1. Create a new Function object (15.3.2.1) with the parameters specified by the FormalParameterList , the Block as the body, and Identifier as its name.
  2. Put this new Function object as the new value of the property named Identifier in the global object or the activation object, as appropriate (see above).