Description

Determines whether a name represents a custom function.

Returns

True, if name can be called as a custom function; False, otherwise.

Category

Function syntax

IsCustomFunction(name)

Parameters

Parameter

Description

name

Name of a custom function. Must not be in quotation marks. If not a defined variable or function name, ColdFusion generates an error.

Usage

The IsCustomFunction function returns True for any function that can be called as a custom function, including functions defined using CFScript function declarations and cffunction tags, and functions that are ColdFusion component methods. For CFC methods, first instantiate the component.

Note: To prevent undefined variable exceptions, always precede IsCustomFunction with an IsDefined test, as shown in the example.

Note: This function does not return true if the function was defined using a function expression, eg:

return 1;
}

For functions defined using function expressions, use isClosure().

Example

 

<cfscript>

// Non-customfunction

n1=1;
n2=1;
sum = n1 + n2;
result = IIf(3 > "#sum#" , DE("Greater"), DE("Lesser"))
writeoutput("Is it a customFunction: " & isCustomFunction(result) & "<br>");

// CustomFunction

function2 = function (sum) {};
writeoutput("Is it a customFunction: " & isCustomFunction(function2));
</cfscript>

Output

Is it customFunction: NO
Is it a customFunction: YES

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy