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 trial
what does the super()__getattribute__(item) here mean?
I'd like to ask a question about the
super() function used here.
From previous courses I see that
super() is used as a subclass to inherent the functions of its superclass.
Here I'm kind of confused about the code this line:
What I thought is that
super() here let the
__getattribute__ method jump out of the function to the class
JavaScirptObject level, so is that a new situation that
super() can be used rather than inheritance of classes?
Look forward to any further explanation about this.
[MOD: added ` formatting -cf]
Wow, this should be a must-read for everyone who is watching this video.
Chris FreemanTreehouse Moderator 68,423 Points
Good Question. Let's review exactly what
super() is providing in the
First, as Kenneth said, the
__getattribute__() method is called whenever a attribute is referenced using the "dot notation", as in, object.attribute.
__getattribute__() is called on a
dict is the only parent. Since a
__getattribute__ method has been defined, the method
dict.__getattribute__() would be completely ignored, that is "overridden".
dict data. To allow access to these "actual attributes", a
super() call is made to access the unaltered version of
__getattribute__ that would have been inherited from the parent
dict had a local method not overridden it.
To be clearer, while
super() allows access to the parent class's version of
__getattribute__, it is executed in the context of the
dict class attributes` if they exist.
Why go through this extra step of including
super()? Because the inherited version of
__getattribute__ also contains the code to properly raise errors if the requested attribute is not found.
Please post back if you need more help on this. Good luck!!