198
Chapter 10: Writing and Calling User-Defined Functions
Defining functions in CFScript
You define functions using CFScript in a manner similar to defining JavaScript functions. You
can define multiple functions in a single CFScript block.
Note:
For more information on using CFScript, see
Chapter 6, “Extending ColdFusion Pages with
CFML Scripting,” on page 127
.
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:
The body of the function definition must consist of one or more valid CFScript statements. The
body must be in curly braces, even if it is a single statement.
The following two statements are allowed only in function definitions:
Function variable
Description
functionName
The name of the function. You cannot use the name of a standard
ColdFusion function or any name that starts with “cf”. You cannot use the
same name for two different function definitions. Function names cannot
include periods.
argName1...
Names of the arguments required by the function. The number of arguments
passed into the function must equal or exceed the number of arguments in
the parentheses at the start of the function definition. If the calling page omits
any of the required arguments, ColdFusion generates a mismatched
argument count error.
Statement
Description
var
variableName = expression
;
Creates and initializes a variable that is local to the function
(function variable). This variable has meaning only inside the
function and is not saved between calls to the function. It has
precedence in the function body over any variables with the same
name that exist in any other scopes. You never prefix a function
variable with a scope identifier, and the name cannot include
periods. The initial value of the variable is the result of evaluating
the expression. The expression can be any valid ColdFusion
expression, including a constant or even another UDF.
All
var
statements must be at the top of the function declaration,
before any other statements. You must initialize all variables when
you declare them. You cannot use the same name for a function
variable and an argument.
Each var statement can initialize only one variable.
You should use the var statement to initialize all function-only
variables, including loop counters and temporary variables.
return
expression
;
Evaluates expression (which can be a variable), returns its value to
the page that called the function, and exits the function. You can
return any ColdFusion variable type.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...