This section describes how CFCs interact with ColdFusion scopes and use local variables, including the following topics:
Note: Components also have a Super keyword that is sometimes called a scope. For information on the Super keyword, see Using the Super keyword.
The This scope is available within the CFC and is shared by all CFC methods. It is also available in the base component (if the CFC is a child component), on the page that instantiates the CFC, and all CFML pages included by the CFC.
Inside the CFC, you define and access This scope variables by using the prefix This, as in the following line:
<cfset This.color="green">
In the calling page, you can define and access CFC This scope variables by using the CFC instance name as the prefix. For example, if you create a CFC instance named car
and, within the car
CFC specify <cfset This.color=
"green">
, a ColdFusion page that instantiates the CFC could refer to the component's color property as #car.color#
.
Variable values in the This scope last as long as the CFC instance exists and, therefore, can persist between calls to methods of a CFC instance.
Note: The This scope identifier works like the This keyword of JavaScript and ActionScript. CFCs do not follow the Java class model, and the This keyword behaves differently in ColdFusion MX than in Java. In Java, This is a private scope, whereas in ColdFusion, it is a public scope.