Forgot to mention, the other common place you'll see it is in constructors
or anywhere else you find yourself with method arguments that match the name
of an instance variable.

public function Person(fname:String,lname:String) {
this.fame = fname;
this.lname = lname;
}

Is it good practice? Probably not.

is it commonly seen in code? Definitely.

Spike

On 10/28/05, Spike <[EMAIL PROTECTED]> wrote:
>
> Passing a reference to the current object is not the only place where
> using the this prefix is useful.
>
> If you come along maintain someone's code 6 months from now and you find a
> complex method of 200 lines of so, it's useful to have the this prefix to
> distinguish between variables that are local to the function and those that
> are available to the instance.
>
> Using the this prefix in your code is more likely to make you look like an
> obsessively meticulious programmer than a newbie in my experience.
>
> If the IDE you use automatically highlights the instance variables then
> there isn't much point in using the this prefix that way, but it's certainly
> a valid excuse for doing it.
>
> Spike
>
> On 10/28/05, A.Cicak <[EMAIL PROTECTED]> wrote:
> >
> > Well, I dont agree, "this" keyword refers to current class, so its only
> > more
> > typing to include it, and making code less
> > readable. Only reason keyword "this" exists is if you want to pass
> > reference
> > to current object somewhere, in which case
> > you must use "this". To me using "this" in your code makes you look like
> > wannabe-programmer, :) But I gues its matter of taste. btw, old VB does
> > not
> > have "this" keyword, and if you were reffering to VB(.NET), it is more
> > OOP
> > and more complex than AS3, so I gues programmers in 
> > VB.NET<http://VB.NET>(if there are
> > some, since C# is there) are not wannabe-programmers :)
> >
> >
> > "ryanm" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > >> What I don't get is why it needs "this.addChild " instead of just
> > >> addChild. I've been sick of the keyword "this" for a long time and
> > have
> > >> since avoided it in AS2.
> > >>
> > >> Any reason that it needs to be back in for AS3?
> > >>
> > > Maybe because it's one of the most useful scope references ever
> > > invented?
> > >
> > > The fundamental concept that you seem to miss is that "addChild" is
> > > meaningless by itself, it is a method of an object (in proper OOP
> > > development), and if you just say "addChild", who is adding the child?
> > You
> > > need a reference. You could do it like this if you like:
> > >
> > > class Game extends MovieClip {
> > > var world:MovieClip;
> > > var bg:MovieClip;
> > > function Game(){
> > > var GameReference:Game = this;
> > > world = new MovieClip();
> > >
> > > GameReference.addChild( world );
> > >
> > > bg = new MovieClip();
> > > world.addChild( bg );
> > > }
> > > }
> > >
> > > The point is, you shouldn't use functions that aren't attached to
> > > objects, it's bad form, and it's thoroughlly confusing to people who
> > later
> > > have to maintain your code. Besides, it makes you look like one of
> > those
> > > wannabe-programmer VB guys. ;-)
> > >
> > > ryanm
> > > _______________________________________________
> > > 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
> >
>
>
>
> --
> --------------------------------------------
> Stephen Milligan
> Do you do the Badger?
> http://www.yellowbadger.com
>
> Do you cfeclipse? http://www.cfeclipse.org
>
>


--
--------------------------------------------
Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to