views:

755

answers:

1

This question might be naive as I'm new to ColdFusion programming.

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

f2 is being called in a cfm file.

My question - Is this the right way to do it? Can I invoke f1 from f2?

I can as well merge f1 into f2, but I would like keep f1 as a separate function.

+9  A: 

Yes, you can call f1 from f2 in ColdFusion if both functions are part of the same component. (They don't have to 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 lots of good reasons to call one function from another. It's called function composition.

Patrick McElhaney
Yeah, I got it now.Its something like <cfinvoke method="functionName" ...></cfinvoke>thanx
Andriyev
You don't actually need to use cfinvoke to call the second function unless you need a new instance of the object. You can simply call it like any other function (as Patrick shows in his example).
Ben Doom