• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. ColdFusion Scripting > User-Defined Functions in <cfscript>

User-Defined Functions in <cfscript>

To create a custom function using <cfscript>, you declare your function just as you would in JavaScript, using the function keyword. Like JavaScript, UDFs can accept and return values and can be embedded within other functions. And because UDFs support recursion, you can call each function from within the function itself.

Listing 12.12 shows an example of a UDF named TitleCase() that takes a string as its one argument and returns the string converted to title case (with the first letter of each word capitalized, and the rest in lowercase). TitleCase() can be called like any other function, as shown in the listing.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint