其中一个比另一个好吗?有什么不同?它们似乎是可以互换的
component
{
property name="some_thing" type="string" value="";
}
VS
component
{
this.some_thing = "";
}
cfproperty
发布CF8,'cfproperty'允许设置一个隐式的setter / getter。
它还用于创建Web服务和ORM应用程序,并具有大量配置属性:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-p-q/cfproperty.html
二传手/吸气
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;
}
}
在模板'foo.cfm'中:
foo = new com.foo();
WriteDump(var=foo.getBar());
// foo
'这个'范围
可以在组件的内部和外部访问“this”范围。
com / foo.cfc
component {
// set properties & variables above any component methods
this.bar = 'foo';
function init(){
return this;
}
}
在模板'foo.cfm'中:
foo = new com.foo();
WriteDump(var=foo.bar);
// foo
组件中的“变量”范围
无法从组件外部访问组件中的变量范围。