Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
Cannikinn #1
Optional Arguments in a CFC
Let's say I have the following function in a CFC:
<cffunction name="init" access="public" output="false">
<cfargument name="id" type="numeric" required="true">
<cfargument name="name" type="string" required="false" default="">
<cfargument name="age" type="numeric" required="false" default="0">
...
</cffunction>
Now, if I instantiate this object using <cfobject> (rather than <cfinvoke) is
there a way to call this method and pass in the id and age, but not the name?
Or do they have to appear in that order? In other words, is there a way to
define which arguments you're passing in as the optional ones? For example:
<cfobject component="com.cfcs.user" name="User">
<cfset User.init(13,24)>
I know that with <cfinvoke> you can actually say which are which using
<cfinvokeargument>, but there are times when I'd like to create an object so
that I can call it several times on the same page without the overhead of
constantly invoking the component over and over.
I believe Java does this (I'm not sure of the syntax), but Ruby does it like
so:
User.init(:id => 13, :age => 24)
Cannikinn Guest
-
numberformat - is optional no longer optional?
Hey all, we just switched to mx. mx 7 is on our horizon, but not close enough for me. I have a problem with numberformat that i did not have on... -
Optional properties
If you have a data class, Person, with two properties, FirstName and LastName, and at a later stage you want to add a new optional property to the... -
WSDL and Optional Parameters
Since there's no way to create a c# method with optional, or nullable parameters. And since you can't write an overloaded web method. Is it... -
Optional Parameters ASP to SQL stored procedure
Hi there, Can someone help, this is driving me crazy I have written a stored procedure in sql with input, output and return parameters. This... -
preg_match_all optional subpattern
Using preg_match_all, I need to capture a list of first and last names plus an optional country code proceeding them. For example: ... -
TA-Selene #2
Re: Optional Arguments in a CFC
You can specify the argument names:
<cfset User.init(id=13,age=24)>
TA-Selene Guest
-
Sfumato #3
Re: Optional Arguments in a CFC
Or you can build a structure of arguments.
<cfset args = structNew()>
<cfset args.id = 13>
<cfset args.age = 24>
<cfset User.init(args)>
Jesse Monson
Sfumato Guest
-



Reply With Quote

