Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are these two components different?

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 = "";
}
like image 815
Patrick Schomburg Avatar asked Mar 16 '26 11:03

Patrick Schomburg


1 Answers

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.

like image 149
Charles Robertson Avatar answered Mar 18 '26 01:03

Charles Robertson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!