• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Two questions

Participant ,
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

How can I call a function name dynamically?
i.e. I have a bunch of validation functions that I need to call dynamically. - any thoughts?

AND... is there a method of telling coldfusion to include all files in a particular directory (without the song and dance of listing the directory, looping through the list etc.. )

-sean
TOPICS
Advanced techniques

Views

368

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Dec 01, 2006 Dec 01, 2006
Hi Dan;

Would you please "elaborate" on the "evaluate" <grin>

I've looked at that function several times, but for some reason or another it's correct use seems to evade me.

Q2... yea wild cards don't work Ho-well

-sean

Votes

Translate

Translate
LEGEND ,
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

answer 1 - use evaluate

answer 2 - proably not, but you could always try to use a wildcard. Or, you could write a master include that contains all the other cfincludes. This would allow you to specify the order in which the files run.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

Hi Dan;

Would you please "elaborate" on the "evaluate" <grin>

I've looked at that function several times, but for some reason or another it's correct use seems to evade me.

Q2... yea wild cards don't work Ho-well

-sean

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

LATEST
got it..

#Evaluate(FunToRun&"(RunAgainst)")#

wish I understood it completely though.... thanks for the pointing of the right direction.

-sean

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

> answer 1 - use evaluate

As a last resort, maybe.

// some basic functions
function f(){
return true;
}

function g(){
return false;
}

// now use a static name, fnToCall, to dynamically call different functions
fnToCall = f; // "f" being the function we defined above
writeOutput(fnToCall()); // outputs "true";

fToCall = g;
writeOutput(fnToCall()); // now outputs "false";

Functions can be assigned to variables just like any other value / variable
/ object.


> answer 2 - proably not,

Just "no, you can't". You need the song and dance. But if it's the sort
of thing you're doing on a regular basis (can't think why you would be, to
be honest), then you should write a UDF that does it, and the you only have
to sing and dance once. Thereafter: use the UDF.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation