View comments | RSS feed

Rules for function definitions

The following rules apply to functions that you define using CFScript or the cffunction tag:

You can use tags or CFScript to create a UDF. Each technique has advantages and disadvantages.


ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


Ashish-Saxena said on Jul 21, 2007 at 9:21 AM :
In respect of first rule. Following code give error as: Entity has incorrect type for being called as a function.
<cfscript>
function Add(a,b)
{
Add = a +b;
return Add;
}
</cfscript>
Addition of 5 and 4 is <cfoutput>#Add(5,4)#</cfoutput><br />
Addition of 2 and 3 is <cfoutput>#Add(2,3)#</cfoutput>

First time calling Add(5,4) is ok, but inside of Add(a,b) we redefined “Add” as simple variable which is now available on the calling page as simple variable rather than as a function name, and will give error on second call of Add(2,3)

The code will be corrected by two ways:
(1) if we use: “var Add = a +b;” instead of “Add = a +b;”
(2) or we use different variable name not same as function name like:
Addition = a +b;
return Addition;

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00001006.htm