Adobe COLDFUSION 9 Manual page 159

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Determining where to create a user-defined function
You can define a function in the following places:
• In a ColdFusion component. If you organize your functions in ColdFusion components, you use the functions as
described in
"Using ColdFusion
• On the page where it is called. You can even define it below the place on the page where it is called, but this poor
coding practice can result in confusing code.
• On a page that you include using a
called. For example, you can define all the functions for your application's on a single page and place a
tag at the top of pages that use the functions.
• On any page that places the function name in a scope common with the page on which you call the function. For
more information on UDF scoping, see
• On the Application.cfc or Application.cfm page. For more information, see
ColdFusion
Application" on page 235.
For recommendations on selecting where you define functions, see the sections
include
files" on page 173 and
About creating functions using CFScript
You use the
statement to define the function in CFScript. CFScript function definitions have the following
function
features and limitations:
• The function definition syntax is familiar to anyone who uses JavaScript or most programming languages.
• CFScript is efficient for writing business logic, such as expressions and conditional operations.
• CFScript function definitions cannot include CFML tags.
The following is a CFScript definition for a function that returns a power of 2:
<cfscript>
function twoPower(exponent) {
return 2^exponent;
}
</cfscript>
For more information on how to use CFScript to define a function, see
Defining functions in CFScript
You define functions using CFScript in a similar manner defining JavaScript functions. You can define multiple
functions in a single CFScript block.
Note: For more information on using CFScript, see
CFScript function definition syntax
A CFScript function definition has the following syntax:
function functionName( [argName1[, argName2...]] )
{
CFScript Statements
}
The following table describes the function variables:
components" on page 189.
tag. The
cfinclude
"Specifying the scope of a
"Specifying the scope of a
function" on page 173.
"Extending ColdFusion Pages with CFML
Last updated 8/5/2010
tag must be executed before the function gets
cfinclude
function" on page 173.
"Designing and Optimizing a
"Using Application.cfm and function
"Defining functions in
154
cfinclude
CFScript" on page 154.
Scripting" on page 106.

Advertisement

Table of Contents
loading

Table of Contents