User Guide Cancel

Built-in functions as first class citizen

The ColdFusion built-in functions will be treated as ‘first-class’ functions so that any built-in function can be passed as an argument.

For instance, this is valid:

<cfscript>
function convertCaseForArray(Array array, function convertor)
{
for (var i=1; i <= arrayLen(array); i++){
array[i] = convertor(array[i]);
}
return array;
}
// lcase built-in function is being passed as callback.
resultantArray = convertCaseForArray(['One', 'Two','Three'], lcase);
writedump(resultantArray);
</cfscript>
<cfscript> function convertCaseForArray(Array array, function convertor) { for (var i=1; i <= arrayLen(array); i++){ array[i] = convertor(array[i]); } return array; } // lcase built-in function is being passed as callback. resultantArray = convertCaseForArray(['One', 'Two','Three'], lcase); writedump(resultantArray); </cfscript>
<cfscript>
function convertCaseForArray(Array array, function convertor)
{
for (var i=1; i <= arrayLen(array); i++){
array[i] = convertor(array[i]);
} 
return array;
}

// lcase built-in function is being passed as callback.
resultantArray = convertCaseForArray(['One', 'Two','Three'], lcase); 

writedump(resultantArray);
</cfscript>

Now, you can treat the built-in CFML functions  like ucase() as objects, being able to assign them to variables, and pass them as arguments.

Get help faster and easier

New user?

Adobe MAX 25

Adobe MAX

The Creativity Conference

Oct 28–30 Los Angeles and online

Adobe MAX

The Creativity Conference

Oct 28–30 Los Angeles and online

Adobe MAX 25

Adobe MAX

The Creativity Conference

Oct 28–30 Los Angeles and online

Adobe MAX

The Creativity Conference

Oct 28–30 Los Angeles and online