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.
Nour El-din El-helw8,241 Points
Constructor methods requirement in classes
I just have little question. When are constructor methods not required in a class? I only thought of one instance of this which is one when we don't need any properties, anything else?
Zack Jackson30,220 Points
From what I've gathered, the constructor method is typically used for calling super and for initializing props. Initializing props in the constructor could avoid potential errors downstream in the code if you forget to initialize for some reason. You can also use a constructor method to set default values when initialized.
That being said, I don't think that constructor methods should be used unless it's really necessary to do so.