Passing arguments into an instance method call
As you have seen in the previous examples, we have sent parameters into the methods on our pages. There are two options available to send your arguments into your method call on an instantiated object.
As a list
You can send the two arguments through as a comma-delimited list. If you use this option, the order of the parameters you pass into the function call must match the order of arguments defined within the method.
In our personalGreeting()
function the first name is the first argument, and the last name is the second argument, therefore you would do the following to call the method:
<cfset strPersonalGreeting = objGreeting.personalGreeting("Daft","Vader") />
Listing 1.26
As named values
An alternative method of sending arguments into a function is to use named values. This option ensures that the values passed through are assigned to the correct argument within the method. This means you do not have to place the parameters within the function call in any specific order, as the name of the parameter will match the name of the argument within the method.
<cfset strPersonalGreeting = objGreeting.personalGreeting(firstName="Daft",lastName="Vader") />
Listing 1.27
As an argumentCollection
As mentioned earlier, we also have the ability to send arguments through to the method using the argumentCollection
attribute, and send through a structure of values.