Adobe COLDFUSION 9 Manual page 164

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
You can call a UDF in two ways:
• With unnamed, positional arguments, as you would call a built-in function
• With named arguments, as you would use attributes in a tag
You can use either technique for any function. However, if you use named arguments, use the same argument names
to call the function as you use to define the function. You cannot call a function with a mixture of named and unnamed
arguments.
One example of a user-defined function is a TotalInterest function that calculates loan payments based on a principal
amount, annual percentage, and loan duration in months. (The definition of this function, see
function
example" on page 171). You can call the function without argument names on a form action page, as follows:
<cfoutput>
Interest: #TotalInterest(Form.Principal, Form.Percent, Form.Months)#
</cfoutput>
You can call the function with argument names, as follows:
<cfoutput>
Interest: #TotalInterest(principal=Form.Principal, annualPercent=Form.Percent,
months=Form.Months)#
</cfoutput>
Working with arguments and variables in functions
Good argument naming practice
Use an argument name that represents its use. For example, the following code is unlikely to result in confusion:
<cfscript>
function SumN(Addend1,Addend2)
{ return Addend1 + Addend2; }
</cfscript>
<cfset x = 10>
<cfset y = 12>
<cfoutput>#SumN(x,y)#</cfoutput>
The following, similar code is more likely to result in programming errors:
<cfscript>
function SumN(x,y)
{ return x + y; }
</cfscript>
<cfset x = 10>
<cfset y = 12>
<cfoutput>#SumN(x,y)#<cfoutput>
Passing arguments
ColdFusion passes the following data types to the function by value:
• Integers
• Real numbers
• Strings (including lists)
• Date-time objects
Last updated 8/5/2010
159
"A user-defined

Advertisement

Table of Contents
loading

Table of Contents