Yes, this is commonly referred to as the "unnamed scope" in CFCsI think you mean putting code within the CFCOMPONENT tags, but outside of any CFFUNCTION tags.
No it isn't.
The code between CFCOMPONENT tags outside CFFUNCTION is NOT A SCOPE AT ALL!!
(except in the lexical sense - don't get me started)
Variables have scopes. You're talking about a region of code which has nothing to do with scopes in ColdFusion.
and is the only true private scope (contrary to some posts on cf-talk and elsewhere, the "this" scope is not private as in Java).
"this" is NOT a scope in Java.
Example:
<cfcomponent>
<!--- pseudo-constructor code here --->
...
<cfset protectedVar = "uses unnamed scope" />
<cfset this.publicVar = "uses 'this' scope" />
...
<!--- end of pseudo-constructor code --->
<cffunction name="foo">
<cfset protectedVar = "change var in unnamed scope" />
<cfset this.publicVar = "change var in 'this' scope" />
</cfunction>
</cfcomponent>It should be clear from this example that the 'pseudo-constructor' has nothing to do with scopes.
It only gets executed on the first invocation of the object, not with each method call.The code will be executed when each component is instantiated or invoked, but I'm not sure if it will actually run on the execution of each method within that component.
Correct. Note that <cfinvoke component="bar" method="foo" /> creates an instance, runs the pseudo-constructor and then invokes the method.
You are probably better off having another method in your component (or
somewhere) that is specifically called in each method rather than
relying on the "constructor". Who knows, that behaviour could change in
a future version of CF.
I agree. I recommend having a function called 'init()' so that the behavior mimics how you handle Java objects:
<cfset jObj = createObject("java","SomeClass") />
<cfset jObj.init(1,2,3) /> <cfset cfcObj = createObject("component","mycfc") />
<cfset cfcObj.init(1,2,3) />Consistency is important.
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive." -- Margaret Atwood
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
