Setters in a component


hi,

 

i made mistake of not scoping local variable in component's function. variable had same name 1 of propeties in component, , had unexpected effect of overwriting value of property. in other words, forgetting scope variable made behave setter.

 

i know solution use right scope in each situation. however, expect handle properties using getters , setters, know why overwrite property, feels unexpected me.

 

have @ example, hope make question clearer.

 

thanks!

 

xavier

 

 

component:

component      displayname="mycomponent"      accessors="true"      persistent="true" {      property name="foo" type="string" default="bar";            function init(){           return this;      }            function usingsetter(required string newvalue){           setfoo(arguments.newvalue);      }            function dosomething(){           // not related property. happen name local variable 'foo'           var foo = 'foobar';           return true;      }            function dosomethingelse(){           // not related property. happen name local variable 'foo', without var keyword           foo = 'choo';           return true;      } } 

 

page:

     mycomponentinstance = new mycomponent();      writedump(var=mycomponentinstance, label="just initialized mycomponent. property has default value");            mycomponentinstance.usingsetter('qux');      writedump(var=mycomponentinstance, label="normal way of setting value of property");            mycomponentinstance.dosomething();      writedump(var=mycomponentinstance, label="that doesn't change value of property");            mycomponentinstance.dosomethingelse();      writedump(var=mycomponentinstance, label="i not expect update value of property, behaved setter. why?"); 

 

output:

setter.png



More discussions in ColdFusion


adobe

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account