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 trialjimvalerio
Courses Plus Student 595 PointsWhat does the "m" stands for as a prefix to the variable? Craig said member? What is it for?
Cant' we not use any variable without "m"?
1 Answer
Nicolas Hampton
44,638 PointsThe m for member is a naming convention, and isn't needed for the code to work. However, it will make the source code easier to understand, as a member variable is one that limits it's scope to the class that it's in. Member variables are therefore made private for the most part, so they are working parts of the object not exposed to the outside world. Think of a radio, and how there's a lot of parts inside a radio that the user doesn't need to know about, that are inside the radio in order for it to work. The m in front of the member variable helps us remember that this value can only be accessed inside the object, like a transistor inside a radio.
jimvalerio
Courses Plus Student 595 Pointsjimvalerio
Courses Plus Student 595 PointsWow! quick response. Thanks.
Nicolas Hampton
44,638 PointsNicolas Hampton
44,638 PointsNo problem, anytime Jim! Happy coding!
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherNicolas;
Great explanation!
Jim;
You will also find the
this.varName
used frequently in lieu of them
prefix tovarName
. They, typically, mean the same thing but some programmers likem
while others stick with thethis.
version.Happy coding,
Ken