这两个组件有何不同?
How are these two components different?
其中一个比另一个好吗?有什么不同?它们似乎可以互换
component
{
property name="some_thing" type="string" value="";
}
对
component
{
this.some_thing = "";
}
cf属性
Post CF8,'cfproperty' 允许设置隐式 setter/getter。
它还用于创建 Web 服务和 ORM 应用程序,并具有大量配置属性:
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;
}
}
在模板中 'foo.cfm':
foo = new com.foo();
WriteDump(var=foo.getBar());
// foo
'this'范围
'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
'variables' 组件内的范围
无法从组件外部访问组件内的变量作用域。
其中一个比另一个好吗?有什么不同?它们似乎可以互换
component
{
property name="some_thing" type="string" value="";
}
对
component
{
this.some_thing = "";
}
cf属性
Post CF8,'cfproperty' 允许设置隐式 setter/getter。
它还用于创建 Web 服务和 ORM 应用程序,并具有大量配置属性:
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;
}
}
在模板中 'foo.cfm':
foo = new com.foo();
WriteDump(var=foo.getBar());
// foo
'this'范围
'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
'variables' 组件内的范围
无法从组件外部访问组件内的变量作用域。