
154
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
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 components
” on page 189.
•
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
cfinclude
tag. The
cfinclude
tag must be executed before the function gets
called. For example, you can define all the functions for your application’s on a single page and place a
cfinclude
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 “
Specifying the scope of a function
” on page 173.
•
On the Application.cfc or Application.cfm page. For more information, see “
Designing and Optimizing a
ColdFusion Application
” on page 235.
For recommendations on selecting where you define functions, see the sections “
Using Application.cfm and function
include files
” on page 173 and “
Specifying the scope of a function
” on page 173.
About creating functions using CFScript
You use the
function
statement to define the function in CFScript. CFScript function definitions have the following
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
” on page 154.
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 “
Extending ColdFusion Pages with CFML Scripting
” on page
106.
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:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...