ColdFusion: call cffunction from the same component

This question may be naive as I am new to ColdFusion programming.

I have a task for which I wrote a function f1 inside a component. I want to call f1 from another function f2 defined in the same component.

f2 is called in the cfm file.

My question is. Is it correct? Can I call f1 from f2 ?

I can also combine f1 into f2 , but I would like to keep f1 as a separate function.

+4
source share
2 answers

Yes, you can call f1 from f2 in ColdFusion if both functions are part of the same component. (They should not be in the same component, but if they are, the answer is always yes.)

  <cffunction name="f2"> ... <cfset result_of_f1 = f1()> ... </cffunction> <cffunction name="f1"> ... </cffunction> 

There are many good reasons to call one function from another. It is called the composition of functions .

+12
source

In Coldfusion 10 and Railo 4, you can create composite functions using the Underscore.cfc library :

 _ = new Underscore();// instantiate the library f1 = function (message) { return "hello " & message; }; f2 = function (toOutput) { writeOutput(toOutput); }; sayHelloTo = _.compose(f2, f1); sayHelloTo("world!");// output: "hello world!" 

(Note: I wrote the Underscore.cfc library)

0
source

All Articles