"In practice, you're right and I try not to name any parameters the same as
a field name to avoid "this" confusion.  Don't tell anyone, but sometimes I
don't even use "this". :)"

So this is wrong?

function MyClass (myParam1:Number, myParam2:String)
{
        this.myParam1 = myParam1;
        this.myParam2 = myParam2;
}

For me this method seems much easier to read and it even refers to naming
parameters this way in the adobe best-practices article.

Why try and come up with 2 names for the same thing, when one will suffice
just fine?

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of JOR
Sent: Tuesday, October 10, 2006 5:52 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Moving to AS2, array always undefined

A bad practice most likely, but not technically wrong.  I do see it in 
text books from time to time.  I was just mentioning it as a case where 
"this" *would* be needed as opposed to speaking in absolutes.

In practice, you're right and I try not to name any parameters the same 
as a field name to avoid "this" confusion.  Don't tell anyone, but 
sometimes I don't even use "this". :)

James O'Reilly  -  Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design . Code . Train



Steven Sacks | BLITZ wrote:
> Correct me if I'm wrong, but it looks like your rationale is entirely
> based on an argument name being identical to a class variable name.  I
> might be looking at this too simply, but shouldn't you just use a
> different argument name if it clashes with a class variable name?
> 
> -Steven
> 
> 
> 
>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:flashcoders-
>>[EMAIL PROTECTED] On Behalf Of JOR
>>Sent: Tuesday, October 10, 2006 1:19 PM
>>To: Flashcoders mailing list
>>Subject: Re: [Flashcoders] Moving to AS2, array always undefined
>>
>>Actually, the "need" is dependent on the implementation.
>>
>>It was my understanding that AS first looks to the local scope for the
>>existence of a variable then works up to find it.  By using "this" you
>>were explicitly telling flash that the var isn't local to the function
>>but rather belongs to the object cutting out a step for the VM.
>>
>>Therefore, something like the following becomes possible and the use
> 
> of
> 
>>"this" becomes necessary:
>>
>>class MyConstructor {
>>   private var target:MovieClip;
>>   public function MyConstructor (target:MovieClip) {
>>     this.target = target;
>>   }
>>}
>>
>>Because you can not do this:
>>
>>class MyConstructor {
>>   private var target:MovieClip;
>>   public function MyConstructor (target:MovieClip) {
>>     target = target; // ?
>>   }
>>}
>>
>>However, depending on your naming conventions you "might" not have to
>>use "this" if you did something like the following:
>>
>>class MyConstructor {
>>   private var _target:MovieClip;
>>   public function MyConstructor (target:MovieClip) {
>>     _target = target;
>>   }
>>}
>>
>>Even still, I think the VM might check for the existence of a var
> 
> named
> 
>>_target local to the constructor function before locating the object's
>>field named _target.
>>
>>It's been a while since I've done anything in AS1 so I may be way off
>>here but I thought I remembered "this" being necessary because at
> 
> weird
> 
>>times the VM would think you were trying to instantiate a local var if
>>you didn't use "this".  Particularly in "on (something)" event
> 
> handlers.
> 
>>Maybe I'm thinking of _global, or perhaps both.  This, I'm not sure
>>about... if you'll excuse the pun. :)
> 
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to