问题
Is there a way to explicitly reference the THIS scope defined in Application.cfc?
Say I have an Application.cfc like this:
component {
this.name="MyApplication"
..
I know that from any page in the site, you can access this.name this way...
<cfoutput>#this.name#</cfoutput>
...but if you are in another component, how would you reach the Application.cfc's "this" scope? Is it possible without handing the var off?
Adobe documentation says that you can reference the "THIS" scope by using the instance or object name as a prefix. I tried Application.this.name but it didn't work.
回答1:
Most of the things that are set in "this" in Application.cfc are not accessible outside the execution of it. ColdFusion copies this.name into application.name at runtime, so you can access application.name from anywhere in your application. For the other settings in "this", they appear to be accessible from your pages because the pages are included into the application.cfc execution cycle by the OnRequest() method.
Once you instantiate a CFC and work inside it's methods, the context of "this" changes to the constructor of that CFC.
来源:https://stackoverflow.com/questions/23795753/in-coldfusion-how-do-you-explicitly-reference-the-this-scope-defined-in-appli