The invoke() Function Will Accept Three Kinds Of Argument Collection Formats In ColdFusion

Earlier, when I was blogging about how the invoke() function can be used to dynamically invoke Java methods, I realized that the ColdFusion documentation didn't really explain how to format the "arguments" argument of the invoke() function. ColdFusion function invocation, in general, is extremely dynamic allowing for both named and ordered arguments as well as a sort of hybrid argument collection format. As such, I wanted to see which formats were supported by the invoke() function.

To test this, I created a simple user defined function (UDF) that would store a given value in a given struct. It's a completely useless function; but, it will allow us to look at all three types of argument collection formats:

Ordered arguments.

Named arguments.

Hybrid arguments (ie, ordered arguments using named arguments).

And, here's the test:

<cfscript>

// I am the collection being added-to.

collection = {};

// Approach One: Define arguments as an ordered array.

argsArray = [ collection, "foo", "bar" ];

// Approach Two: Define arguments as a named collection.

argsStruct = {

collection: collection,

key: "hello",

value: "world"

};

// Approach Three: Define arguments as a named collection in which the keys are

As you can see, the "arguments" argument of the invoke() function is being passed an array or ordered arguments, a struct of named arguments, and a struct of hybrid "ordered" arguments. And, when we run the above code, we get the following writeDump() output:

struct

foo: barhello: worldwe be: jammin

That's kablamo! As you can see, the invoke() function successfully consumed all three argument collection formats. This is pretty cool. People often forget how magically dynamic ColdFusion can be.

I am the co-founder and lead engineer at InVision App, Inc — the world's leading prototyping,
collaboration & workflow platform. I also rock out in JavaScript and ColdFusion 24x7 and I dream about
promise resolving asynchronously.