Creating User-Defined Functions; Creating Functions Using Cfscript; Creating Functions Using Tags - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

You might call the function with argument names, as follows:
<cfoutput>
Interest: #TotalInterest(principal=Form.Principal, annualPercent=Form.Percent,
months=Form.Months)#
</cfoutput>

Creating user-defined functions

You can use tags or CFScript to create a UDF. Each technique has advantages and disadvantages.

Creating functions using CFScript

You use the
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
CFScript" on page

Creating functions using tags

You use the
cffunction
following features and limitations:
Developers who have a background in CFML or HTML, but no scripting or programming
experience will be more familiar with the syntax.
You can include any ColdFusion tag in your function definition. Therefore, you can create a
function, for example, that accesses a database.
You can embed CFScript code inside the function definition.
The
cffunction
to authorized users or specify how the function can be accessed.
The following code uses the
<cffunction name="twoPower" output=True>
<cfargument name="exponent">
<cfreturn 2^exponent>
</cffunction>
For more information on how to use the
functions using the cffunction tag" on page
statement to define the function in CFScript. CFScript function
198.
tag to define a UDF in CFML. The
tag provides attributes that enable you to easily limit the execution of the tag
cffunction
cffunction
tag to define the exponentiation function:
tag to define a function, see
cffunction
200.

Creating user-defined functions

"Defining functions in
tag syntax has the
"Defining
193

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents