ECMA-262 Core: JavaScript Function Data Type

Navigation Aids -- This Page        Navigation Aids -- This Topic        Navigation Aids -- This Site

Introduction And Review

The topic of JS functions is covered from many perspectives:

Our page entitled "JavaScript Data" will describe how JS data types interplay with the following topics:

Reference Types (also called Composite Data Types)

The Function data type is a member of the reference type group. This group also contains the Array data type and the Object data type. Sometimes all three types, Array, Function and Object are referred to as "Object types" in a generic context.

At our site, we sometimes refer to the reference data types as "composite data types". The reference data types have some unique characteristics when compared to there cousins, the primitive data types.

Function Data Values

There are no pre-defined data values for the Function data type. Pre-defined data values apply to the primitive types, not the reference types.

Creating Function Data

The JS practitioner has three methods available for creating a Function type data structure.

  1. The Function Class Constructor var fArea = new Function("width", "height", "return width*height;");
  2. Function Literal var fArea = function(width, height) { return width * height; }
  3. Function Statement function fArea(width, height) { return width * height; }

Determining Function Data Type

The data type is fairly obvious when using the Function class constructor or the function statement. But when the data is created via a literal statement, then determining the data type is less obvious for the JS interpreter.

When using a literal, the Function type is distinguished from other types using a dynamic or weak typing method. The method involves interrogating the value token of the defining literal. The Function literal is distinguished from all other types by a special syntax of the defining literal and the use of the function keyword. Following the keyword, the function literal consists of a comma separated list of parameter names that are all enclosed by a set of parentheses. This is followed by the function body statements enclosed by a set of curly braces.

Function Class and Class Members

Once our function of the Function type is created, this same function has access to the members of the Function class type.

Using the Function Type

The JS function has many uses:


Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson