Function call (Definition)

A means of invoking a function definition.

A function may be invoked at any time. Typically in a web browser, functions are attached to event handlers belonging to document objects.

A function call consists of the identifier that names the function and a set of parentheses enclosing the optional parameters. The declaration of the function specifies the identifier and the formal parameter list.

The identifier must match letter for letter in the same case.

When a function is called either as a procedure or as part of an expression, there is the possibility of somewhat massive side effects to take place before the function returns. Indeed, it is possible to build a function that actually never returns.

Functions can be called in other documents, other frames and other windows. However, there are some security implications regarding whether those functions are accessible - the calling and called functions must exist in pages that were loaded from the same server or domain unless the security controls can be relaxed.

It is generally easier to call functions in parent windows and frames and then call downwards to their children. This allows some session state to be maintained in the parent's global scope. The parent can be a frameset and need not be a visible window or frame.

If you are using the parent as a means of maintaining state information, you might want to implement accessor functions to store and retrieve state information. This allows the validation of the values to be range checked in one place and for the physical storage implementation to be hidden. This is indicative of a good Object Oriented Programming style.

The result returned by a function call depends on the function script source text.

See also:Arguments object, Calling event handlers, Function, Function code, Function object, Function property, Function prototype, function( ... ) ..., Function(), Function(), Function.arguments[], Function.arity, Function.Class, Function.constructor, Function.length, Function.prototype, Function.toString()


Wrox Instant JavaScript - page - 27