Reputation: 2577
Is one of these better than the other? What's the difference? They seem to be interchangeable
component
{
property name="some_thing" type="string" value="";
}
vs
component
{
this.some_thing = "";
}
Upvotes: 3
Views: 92
Reputation: 1820
cfproperty
Post CF8, 'cfproperty' allows one to set an implicit setter/getter.
It is also used in the creation of web services & ORM applications and has a vast array of configuration properties:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-p-q/cfproperty.html
Setter/getter
com/foo.cfc
component accessors='true' {
// set properties & variables above any component methods
property name='bar' type='string';
this.setBar('foo');
function init(){
return this;
}
}
Within a template 'foo.cfm':
foo = new com.foo();
WriteDump(var=foo.getBar());
// foo
'this' scope
The 'this' scope can be accessed both internally & externally to the component.
com/foo.cfc
component {
// set properties & variables above any component methods
this.bar = 'foo';
function init(){
return this;
}
}
Within a template 'foo.cfm':
foo = new com.foo();
WriteDump(var=foo.bar);
// foo
'variables' scope within a component
The variables scope within a component cannot be accessed from outside the component.
Upvotes: 3