On Monday, Jan 6, 2003, at 13:07 US/Pacific, Adrocknaphobia Jones wrote:
> So Christian says to declare all of your private CFC variables at the
> top of the function like so <cfset var value = 1>.

He means: declare your *local* variables with 'var' at the top of the 
function.

'private' variables live in the unnamed scope. The intent was to use 
'variables' for the private scope but there's a bug that makes 
'variables.x' behave the wrong way inside CF (so don't use variables 
scope inside CFCs!).

> Hal Helms recommends using <cfset this.value = 1>. Both obviously work,
> but I'm wondering what the pros and cons are if any.

'this' is public.

'var' means a variable exists only for the lifetime of a specific 
function call. It is created and initialized on each call to the 
function.

'unnamed scope' and 'this scope' exist for the lifetime of the CFC 
instance - which depends on where the CFC is stored (variables scope, 
session scope, server scope etc). Such variables are created when the 
CFC instance is created and die only when the CFC instance itself dies.

> Off the top of my head, it would seem that 'this' is more functional, 
> as
> it acts like any other scope and can be dumped.

'this' scope can be modified by outside agents:

        <cfscript>
                x = createObject("component","person");
                x.age = -42;
        </cfscript>

Inside the 'person' instance, your functions can access 'this.age' and 
it is the *same* variable as 'x.age' accessed from outside the instance.

If you use the unnamed scope inside your CFC, external code like this 
(while still valid CFML) will not overwrite your 'private' variables.

Sean A Corfield -- Director, Architecture
Web Technology Group -- Macromedia, Inc.
tel: (415) 252-2287 -- cell: (415) 717-8473
aim: seancorfield -- http://www.macromedia.com
An Architect's View -- http://www.corfield.org/blog/

Introducing Macromedia Contribute. Web publishing for everyone.
Learn more at http://www.macromedia.com/contribute

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to