i have a functions which call other functions in different CFC through mapping

61 Views Asked by At

I have few functions which i am trying to call from other CFCs using mappings

but i had clutterred all functions with external functions calls like this:

function a() {
b = new mynewpage.cfc.functionb(arguments);
}
function c() {
c = new mynewpage.cfc.pages.functionc(arguments);
}

so i am trying to focus on creating one function called as invokeme

function invokeme() {
c = new mynewpage.cfc.pages.functionc(arguments);
b = new mynewpage.cfc.functionb(arguments);
}

nut my question is how can use the invokeme function to use in function a and function b

should i use invokeme.b.a()

1

There are 1 best solutions below

0
On

I think something like this should work. I'm not 100% sure though in your context because I don't know what those other functions are doing.

function invokeme(args) {
    return {
        b = new mynewpage.cfc.functionb(argumentCollection=arguments.args);
    }
}
invokeme(someArguments).b.a; //Assuming b returns a component or object.

For example: https://cffiddle.org/app/file?filepath=0def2e60-5ae3-466e-96de-f80bbbd2d78a/302995b7-ed73-48eb-bf97-598d4a825058/9184f40d-05b5-464e-ae49-45450787edf5.cfm

Essentially you nee to return the instance out of the function for use so the result of invokeme will be keys which are references to those instances. Then you can call them. I think this slightly complicates your code. I think it's cleaner to assign the instances explicitly instead of hidden in a function.