Results 1 to 9 of 9
Thread: this
- 11-16-2010, 05:14 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
- 11-16-2010, 05:30 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
"this" is a reference to the instance whose method has been called. It has the same meaning in the expression "this.lolol=lolol".
- 11-16-2010, 05:50 AM #3
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Why on earth someone would assign a variable to refer to 'this' is beyond me. Pass to a method, return from a method, sure, but assign? no clue - seems a bit redundant if you ask me.
Anyway, as pbrockway said, it refers to the instance who's method has been called, or the current instance of the class you are in.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 11-16-2010, 05:54 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
Thanks guys, and yeah singing, the book I am reading has a lot of toy examples =D
- 11-16-2010, 06:00 AM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Ah, its from a book. That explains it then... The redundancy in programming books and official tutorials never ceases to amaze me :rolleyes:
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 11-16-2010, 07:20 AM #6
- 11-16-2010, 09:32 AM #7
look at this link
my personal opinion: even if the keyword is not necessery in a piece of code it makes the code more comprehensible.The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.
- 11-16-2010, 06:29 PM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
- 11-16-2010, 11:59 PM #9
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Redundancy is not Uselessness...
Its still redundant. Not necessarily useless, but it's certainly redundant to show examples that will never/extremely rarely be used, just to show the full capability of a keyword. Assigning something to refer to 'this' is inherently redundant. What are you going to do with it? v = this; v.method(); is a bit pointless if you ask me.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks