Question
Creating Objects from CFCs
I am working on creating a couple of components that will act
as objects in the Application and Session scopes. I have been
looking at examples online and have notices a couple of different
things that I assume are accomplishing the same goal, but wanted to
ask someone.
I understand that the THIS scope is used within the object to store variables. I guess my questions more along the lines of how to initialize those variables.
One method I have seen used is just by declaring at the beginning of the component (as below):
<cfcomponent>
<cfset THIS.var1="lala">
<cfset THIS.var2="toto">
<cffunction....
The other method I have seen is using the method init():
<cfcomponent>
<cffunction name="init" ...>
<cfset THIS.var1="lala">
<cfset THIS.var2="toto">
</cffunction>
I am assuming that they are accomplishing the same task.
If someone can explain the differences between these two methods and if there are benefits to either one it would be greatly appreciated. Thanks!
I understand that the THIS scope is used within the object to store variables. I guess my questions more along the lines of how to initialize those variables.
One method I have seen used is just by declaring at the beginning of the component (as below):
<cfcomponent>
<cfset THIS.var1="lala">
<cfset THIS.var2="toto">
<cffunction....
The other method I have seen is using the method init():
<cfcomponent>
<cffunction name="init" ...>
<cfset THIS.var1="lala">
<cfset THIS.var2="toto">
</cffunction>
I am assuming that they are accomplishing the same task.
If someone can explain the differences between these two methods and if there are benefits to either one it would be greatly appreciated. Thanks!
