Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Subclassing Built-ins

Michael Sothan
Michael Sothan
8,048 Points

What is the purpose of always adding an extra object in front of the method?

I noticed in all of Kenneth's examples he will test using a new object like "jso" and then assign it to a class so he can run his method on it, like

jso = javascriptobject.JavaScriptObject({'name:'  'Kenneth'})

It seems like the 'javascriptobject' in front is redundant. It can't just be?:

jso = JavaScriptObject({'name': 'Kenneth'})

Is it because this newly created class only exists within the "javascriptobject.py" program?

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,227 Points

Is it because this newly created class only exists within the "javascriptobject.py" program? Correct.

If Kenneth had used JavaScriptObject({'name': 'Kenneth'}) then the object JavaScriptObject would be looked for in the current module name space. Including the module name javascriptobject indicates to look for the object in the import module.

Post back if you need more help. Good luck!!