You need the this in any case the scope of the variable or method is not clear. In all other cases the this is not necessary. I don't use it. Tools such as FDT highlight instance properties differently to local or argument variables. This makes it easy to visually detect the scope of a property even if no this is in use.

public var value : String = "";

public function setValue(value : String) : void {
   this.value = value;
}


Am 08.06.2011 08:06, schrieb Cor:
Micky,

There are no stupid questions!
Only stupid people who don't ask their question... and yes, there are stupid 
answers. :-)

As for the prefix, IMO it is unnecessary, but some people find it easier to 
read their code.
I'll will not call myself a pro, but I never use it.

HTH,
Cor


-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Micky Hulse
Sent: woensdag 8 juni 2011 6:55
To: Flash Coders List
Subject: [Flashcoders] using "this" in AS3 classes?

Hi,

Stupid question, but...

Let's say I have some class properties:

private var _mc1:MovieClip;
private var _mc2:MovieClip;

... and methods:

private function baz():void { ... }
private function foo():void { ... }

In my code, would it be overkill to always reference the above examples with a prefix of 
"this"?

For example:

this._mc1 = ...;
this._mc2 = this.mc1;
this.baz();
this.foo();

I could easily do this instead:

_mc1 = ...;
_mc2 = mc1;
baz();
foo();

Sorry if silly question, I am just kinda wondering what the pros do. :)

Best practices?

Thanks!
Micky
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to