Using the 'var' keyword is only allowed inside functions/methods.  It
creates a local variable that only exists for that specific invocation of
the function.  Such variables are immune to race conditions, because they
are bound to a specific invocation.  This is not specific to CFCs, you can
use it in any function definition (including CFSCRIPT functions), in or
outside a CFC.

Using the 'variables' scope creates a private variable accessible only to
your CFC.  It exists as long as the instance of the CFC is around.  Such
variables are NOT immune to race conditions, because they are shared across
the instance, and multiple clients may be calling methods on a single
instance at the same time.

Using the 'this' scope is just like the 'variables' scope, except that the
variables are public, so the can be read or written by client code, as well
as methods of the CFC.

Cheers,
barneyb

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Troy Simpson
> Sent: Tuesday, February 10, 2004 9:38 AM
> To: [EMAIL PROTECTED]
> Subject: [CFCDev] How should I define variable in a CFC?
> 
> All,
> 
> I have been away from coldfusion for about a year or so and 
> now need to 
> get back into in.  I am using ColdFusion MX for this project 
> that I am 
> working on.  I need some clarification if possible.
> 
> How should I define variables in a CFC and why?
> What is the difference between the three?
> 
> <cfcomponent>
>    <cfset var dsn = "DataSourceName">
>    <cfset variables.dsn = "DataSourceName">
>    <cfset this.dsn = "DataSourceName">
> </cfcomponent>
> 
> Thanks,
> Troy
> 
> -- 
> Troy Simpson
>    Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
> North Carolina State University Libraries
> Campus Box 7111 | Raleigh | North Carolina
> ph.919.515.3855 | fax.919.513.3330
> E-mail: [EMAIL PROTECTED]
> 
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
> 
> An archive of the CFCDev list is available at 
> www.mail-archive.com/[EMAIL PROTECTED]
> 

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to