这两个组件有何不同



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

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

vs

component
{
    this.some_thing = "";
}

cfproperty

post cf8," cfproperty"允许设置隐式设置器/getter。

它也用于创建Web Services&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

'这个'范围

可以在内部访问'此'范围;从外部到组件。

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

'变量的范围

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

最新更新