这两个组件有何不同?

问题描述 投票:3回答:1

其中一个比另一个好吗?有什么不同?它们似乎是可以互换的

component
{
    property name="some_thing" type="string" value="";
}

VS

component
{
    this.some_thing = "";
}
coldfusion coldfusion-10 cfml
1个回答
3
投票

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

组件中的“变量”范围

无法从组件外部访问组件中的变量范围。

© www.soinside.com 2019 - 2024. All rights reserved.