A great practice is to put a prefix on member variables to avoid exactly
what Shaun is talking about. I typically use an underscore as follows.
This completely eliminates the need for the "this" even for readability
sake. Additionally I pretty much use only private members. If I want
to expose a property I write a getter and/or setter as appropriate.
public class myClass
{
private var _valueOne:String;
private var _valueTwo:String;
public function myClass( valueOne:String, valueTwo:String )
{
this._valueOne = valueOne; // ok
_valueTwo = valueTwo; // also OK
}
//value one is read only
public function get valueOne():String
{
return _valueOne;
}
//value two is read/write
public function get valueTwo():String
{
return _valueTwo;
}
public function set valueTwo(valueTwo:String):void
{
_valueTwo = valueTwo;
}
}
2 more of my cents :)
Scott
Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com
http://blog.fastlanesw.com
shaun wrote:
Mike Anderson wrote:
Greetings All,
Whenever I study code generated by seasoned programmers (i.e. all the
Adobe people supporting Flex on this list) as well as countless others
on this list, I notice that some use "this" when referencing local
variables contained within a Class.
The last thing I want to do here, is start a heated discussion regarding
"best practices" for programming. My goal on a daily basis, is to
better myself as a programmer, and I want to make sure that the code I
create, conforms to certain standards.
Could some of you please offer your 2 Cents regarding the
advantages/disadvantages of using "this"? Just a quick example:
package
{
public class myClass()
{
private var testVar:String;
public function myClass( value:String )
{
this.testVar = value;
// versus:
testVar = value;
}
}
}
Something to consider is the naming of the function parameters used.
eg)
public class myClass()
{
protected var valueOne:String;
protected var valueTwo:String;
public function myClass( valueOne:String, valueTwo:String )
{
this.valueOne = valueOne; // ok
valueTwo = valueTwo; //?? erk
}
}
}
cheers,
- shaun