Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJ T
19,878 PointsSelf Keyword
I still don't completely understand the self
keyword. I've re-listened to the videos explaining it a couple times, and I've looked it up on StackOverflow, but I can't find anywhere that explains it very well. Can someone explain it to me?
3 Answers
Holger Liesegang
50,595 PointsHi Josh,
let's make this really simple. You've got 3 people (instances/objects) - for example: Britney, Herbert and yourself. Now you might want to refer to Britney's arm, Herber's leg and your head from your point (the actual instance/object) of view/perspective: that would be something like britney.arm, herbert.leg and (your)SELF.head. That's of course not the complete truth of this matter but you might want to think of this like that when starting with object oriented programming :-)
Kind Regards Holger
Patrick Cooney
12,216 PointsSee if this thread from the TTH forums helps.
Aidid Jaafar
Courses Plus Student 4,354 PointsHave you try looking at MDN ?
J T
19,878 PointsJ T
19,878 PointsThanks Holger, that makes a little more sense. So it refers to the instance variable youβre using?
Holger Liesegang
50,595 PointsHolger Liesegang
50,595 PointsYeah, simple put It kinda refers to the properties/methods of the class (self/this) which is trying to use their own properties/methods.