Description

Determines whether a value or expression references a function defined via a function expression, as opposed to a function statement.

Returns

True, if the value represents a function expression; otherwise False.

Category

Syntax

isClosure(value)

See also

History

ColdFusion 10: Added this function.

Parameters

Parameter

Description

value

A value.

Usage

Use this function to determine whether the value or expression represents a function defined via a function expression.

Example

<cfscript>
// a custom function defined via a function statement 
function multiplier(x,y){
return x * y;
}
 
// a custom function defined via a function expression
adder = function(x,y){
return x + y;
};
// a string containing the name of the function reference 
name = "multiplier";
</cfscript>

<cfoutput>

<!--- examples using function references--->

<!---
a function declared via a function statement
IS a custom function,
but IS NOT a "closure"
--->
isCustomFunction(referenceToDeclaredFunction):
#isCustomFunction(multiplier)#<br> <!--- true --->

isClosure(referenceToDeclaredFunction):
#isClosure(multiplier)#<br><hr> <!--- false --->

<!---
a function declared via a function expression
IS NOT a custom function,
but IS a "closure"
--->
isCustomFunction(referenceToFunctionExpression):
#isCustomFunction(adder)#<br> <!--- false --->
isClosure(referenceToFunctionExpression):
#isClosure(adder)#<br><hr> <!--- true --->

 
<!--- examples not using function references--->

<!--- a string IS NOT a custom function, nor is it a closure --->
isCustomFunction(stringContainingNameOfFunctionReference):
#isCustomFunction(name)#<br> <!--- false --->
isClosure(stringContainingNameOfFunctionReference):
#isClosure(name)#<br><hr> <!--- false --->

<!---
a string-literal containing the function expression variable name
is not correct usage: it's just a string
--->
isCustomFunction("adder"):
#isCustomFunction("adder")#<br> <!--- false --->
isClosure("adder"):
#isClosure("adder")#<br><hr> <!--- false --->
</cfoutput>
<cfscript>
// an expression can be evaluated directly
result = isCustomFunction(function(x,y){
return x-y;
}
);
writeOutput("isCustomFunction(inlineExpression): #result#<br>"); // false

result = isClosure(function(x,y){
return x-y;
}
);
writeOutput("isClosure(inlineExpression): #result#<br>"); // true
</cfscript>

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